10
votes

Is it possible to have a conditional installation configuration, slaved wth the Visual Studio configuration environment?

For example, selecting DEBUG or RELEASE configuration, Wix selects different executables in the built installation.

Basically I shall build different installations from the same projects, but they differs by the components. Some components are build from the same project, but built with different preprocessor options.

Of course it is possible to include every required component, and then define features in order to select a specific component for the installation, but I don't want really to redistribute some executables.

Build different Wix projects is the only solution?

3

3 Answers

6
votes

Use the preprocessor, e.g.: <?if?> to conditionally include/exclude components based on configuration.

13
votes

Putting the other two answers and Luca's research together I came up with this solution, which seems to work (note that the string comparison appears to be case sensitive, and the lack of quotes appears to be correct, I've tested this with WiX 3.7):

<?if $(var.Configuration) = Debug ?>
  <!-- DEBUG ONLY -->

  [ ... insert debug only XML here ... ]

  <!-- END DEBUG ONLY -->
<?else?>
  <!-- RELEASE ONLY -->

  [ ... insert release only XML here ... ]

  <!-- END RELEASE ONLY -->
<?endif?>
8
votes

Your wix scripts have access to build parameters, like the Configuration ('debug' or 'release'). You can therefore conditionally include the correct binaries for the current configuration by referencing $(var.Configuartion) in your component declarations:

<Component Id="myProject.dll"
               DiskId="1"
               Guid="*">
  <File Id="myProject.dll"
            Name="myProject.dll"
            Source="..\myProject\bin\$(var.Configuration)\myProject.dll" />
</Component>

When you run the build in release mode, this script will pick up the release version of the binary. Likewise, in debug mode, the debug binary will be picked up. This approach does not require preprocessing - the script makes Configuration-related decisions at build time.