2
votes

I am writing a WXS file for a package I want to install. For the sake of simplicity, let's say I want to install 1 file and then I want to execute a command against it (in my case, it is a public GPG key and I want to import it after the installation is done). Here are the relevant parts of my WXS file:

<CustomAction Id="ImportKey" Directory="INSTALLDIR"
              ExeCommand="[SystemFolder]cmd.exe /C gpg --import keyfile.key"
              Return="check" />

<!-- Install file keyfile.key into C:\GnuPG -->
<Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="INSTALLDIR" Name="GnuPG">
        <Component Id="GnuPGConfiguration" Guid="E9469F1C-A875-1014-A3B3-DEF3264B13C4">
            <File Name="keyfile.key" Id="KeyfileKey" />
        </Component>
    </Directory>
</Directory>

<Feature Id="GnuPGConfiguration" Level="1" Title="GnuPG Configuration">
    <ComponentRef Id="GnuPGConfiguration" />
</Feature>

<!-- Run custom action after files are installed -->
<InstallExecuteSequence>
    <Custom Action="ImportKey" After="InstallFiles">NOT Installed AND NOT PATCH</Custom>
</InstallExecuteSequence>

I can successfully build the MSI. When installing, I use msiexec and turn on logging. There it says that installation fails on the custom action and the correct command is found in the log. Running it manually works. If I comment out execution of the command, the file is installed in the correct location (C:\GnuPG\keyfile.key exists after installation).

Instead of running my GPG command, I tried running dir ant redirected its output to a file. Viewing it, I can see that keyfile.key is not among the files in C:\GnuPG. It seems that the command is run before the file is installed.

Any ideas on what I am doing wrong?

1

1 Answers

6
votes

You need to read and understand:

Installation Phases and In-Script Execution Options for Custom Actions in Windows Installer

You will find yourself considering needing

<CustomAction ... Execute="deferred" and Impersonate="no" ... />

Also you are likely to need to qualify the location of the .key file as your current directory isn't going to be what you think it is.