Search code examples
cmdwixxcopy

Executing a CustomAction in Wix with 'if exist'


Hi I would like to perform the following CustomAction when installing my program:

<!--Include the custom action for overwrite Client.config-->
    <CustomAction Id="SetCmdLineParams" Property="QtExecCA" Value='if exist &quot;[CURRENTDIRECTORY]\Client.config&quot; ("xcopy" /Y &quot;[CURRENTDIRECTORY]\Client.config&quot; &quot;[INSTALLFOLDER]&quot;)' Execute="immediate" />
    <CustomAction Id="QtExecCA" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="check" Impersonate="no"/>

    <!--Include the InstallExecuteSequence for overwrite Client.config-->
    <InstallExecuteSequence>
      <Custom Action="SetCmdLineParams" After="CostFinalize"/>
      <Custom Action="QtExecCA" Before="InstallFinalize" />
    </InstallExecuteSequence>

Unfortunately this doesn't work because: CAQuietExec: Command string must begin with quoted application name.

But if I quote "if exist", then the command does not work. What can I do now?


Solution

  • if exist is a feature of cmd.exe. You'd need to say cmd /c first or create a .bat file and call that.

    Honestly though, this is really fragile code. For one CURRENTDIR isn't always going to be what you think it is. You should write a C++ or C# custom action that uses the OriginalDatabase property to get where the MSI is running from and copy the config file from there.

    Another approach I've used very successfully in the past is to write a utility that can transform a seed MSI by embedding a user provided config file into it. Now the deployment story is simplified.