How to use conditions in features in WiX?
40,072
Solution 1
You need to move your Condition into your Component definition, and use ! (Feature state) instead of & (Feature action) so that it works when you try to add the examples by re-running the install a second time:
<Component Id="example1">
<Condition>!feature1 = 3</Condition>
</Component>
<Component Id="example2">
<Condition>!feature2 = 3</Condition>
</Component>
<Feature Id="feature1">
</Feature>
<Feature Id="feature2">
</Feature>
<Feature Id="examples">
<ComponentRef Id="example1" />
<ComponentRef Id="example2" />
</Feature>
Solution 2
Have you considered making feature1 the parent of feature2? Then feature2 can't be installed unless feature1 will also be installed. No condition necessary.
<Feature Id='core' Title='Core'
Description='ØMQ 1.0.0 core functionality and C++ API' Level='1'>
<ComponentRef Id='Core_include' />
<ComponentRef Id='Core_bin' />
<ComponentRef Id='Core_lib' />
<ComponentRef Id='Core_zmq' />
<ComponentRef Id='cpp_bin' />
<Feature Id='core_perf' Title='core_perf' Description='0MQ core perf'
Level='999'>
<ComponentRef Id='cpp_perf' />
</Feature>
</Feature>
Author by
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I am trying to make simple Windows intaller, and I don't know how to deal with this. I have two features - feature1 and feature2. I want feature2 to be installed only if the user selected feature1 to be installed. So I tried:
<Feature Id='core' Title='Core' Description='ØMQ 1.0.0 core functionality and C++ API' Level='1'> <ComponentRef Id='Core_include' /> <ComponentRef Id='Core_bin' /> <ComponentRef Id='Core_lib' /> <ComponentRef Id='Core_zmq' /> <ComponentRef Id='cpp_bin' /> </Feature> <Feature Id='core_perf' Title='core_perf' Description='0MQ core perf' Level='999'> <Condition Level="0">NOT (&core = "3")</Condition> <ComponentRef Id='cpp_perf' /> </Feature>
But this doesn't install feature core_perf if the user selects feature core.
How can I fix this?