Setting conditions on Components in Wix

12,087

Solution 1

You can confirm by opening your MSI output file using some File compressing/uncompressing software such as 7zip and open the package.cab file inside the opened MSI file. and check whether your files with the id like "mycomponent" is present there or not.

I hope it is expected since it is dependent on the variable and that can be something which even can be set from install command call as install property.

UPDATE: You can amend the WIX like below by using Preprocessor statements, so it can exclude these optional component from the resulting msi

    <?if $(env.MySku) = Enterprise ?>
       <Component Id="mycomponent" Guid="*" Feature="Core">
          <Condition>$(var.Include) = 1</Condition>
          <File Id="mycomponent.file" KeyPath="yes" Source="$(var.BinDir)\mycomponent.file" />      
       </Component>
    <?endif ?>

Solution 2

The condition element is used to determine whether a component gets installed not whether it gets included in the build or not. Also be sure not to confuse Windows Installer properties used in Conditional Statements and preprocessor variables / statements. Two different beasts.

Solution 3

As @RinoTom and @Christopher point out, install-time selection (Condition tag) is very different from build-time selection (?if meta-tag). To be selectable at install time, the included components must be in the .msi . The advantage of this approach is that you can set the properties that determine their conditions, not only at build time, but at install time as well via dialogs or AppSearch.

But what you're asking for is multiple package builds, each tailored to a specific set of conditions, selected at build time. An alternative that might work for you is to define each of the optional components as a Fragment in a separate file. Then for each package configuration, compile only the fragments you want in it:

del /q *.wixobj
candle main_package.wxs
for %%f in (optional_1.wxs optional_5.wxs optional_27.wxs) do candle %%f
light *.wixobj -out tailored_package_A.msi

Since only those fragments you wanted included have been compiled to .wixobj, only they appear in the output package. This scales particularly nicely if you have some components that are always present, but only a handful that are optional.

Share:
12,087
Godsent
Author by

Godsent

Updated on June 04, 2022

Comments

  • Godsent
    Godsent almost 2 years

    In my Wix, I have lots of files included in this way:

    <Component Id="mycomponent" Guid="*" Feature="Core" >
      <Condition>$(var.Include) = 1</Condition>
      <File Id="mycomponent.file" KeyPath="yes" 
            Source="$(var.BinDir)\mycomponent.file" />
    </Component>
    

    So I can pass in a different value of var.Include to generate packages for different environment.

    While the resulting packages do seem to work, however I noticed the size of the packages are always quite big even when I set it to not include these components. It looks as if WiX is always including all components in building the msi, and only chose to not install these components when the package was build with var.Include = 0...

    Is this a normal behavior?

  • Godsent
    Godsent about 11 years
    Ah..thanks..I didn't know this var.include can be overridden from the install command call...I thought it was used to build the package. then a related question I guess is how to amend the wix so it can exclude these optional component from the resulting msi
  • Stein Åsmul
    Stein Åsmul over 9 years
    You can also use an admin install to extract the files in the MSI file instead of a zip tool. Here is another explaination.
  • user922020
    user922020 over 5 years
    That XML is poorly formed. <Condition> doesn't have a closing </Condition>