19

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 (&amp;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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • By the strict meaning of "only if" it sounds like feature1 and feature2 are actually just one feature. Do you really mean that feature2 should only be available if feature1 is installed? – Jared Jul 21 '09 at 12:38
  • Yes, that's right. I want feature2 to be installed ONLY IF feature1 is installed. –  Jul 21 '09 at 12:48
  • 1
    To explain - my application has several different features and then I have example section showing examples of usage of these features. I want if somebody chooses "feature1" and feature "examples" (consists of examples of all features), then I want feature "feature1_examples" to be installed. –  Jul 21 '09 at 12:51

2 Answers2

17

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>
Jared
  • 1,305
  • 9
  • 13
  • 4
    Where is this documented? Feature state = ! and Feature action = &. – Cheeso Apr 28 '10 at 21:54
  • 12
    http://msdn.microsoft.com/en-us/library/aa368012(VS.85).aspx http://www.tramontana.co.hu/wix/lesson6.php#6.2 – Jared Apr 29 '10 at 14:23
  • This might be good with some components, but difficult to manage if you have large number of Components. – Farrukh Waheed Mar 21 '13 at 11:48
  • 1
    Whoever designed this syntax needs to have their head examined. I seriously did not think today that I will be Googling how to specify the `not-equal` condition. – c00000fd Jul 26 '20 at 01:34
  • 1
    @c00000fd this syntax was designed in 1997'ish and was influenced by BASIC since there was a lot of VB/VBScript/VBA in the installation space back then. If it was designed or modernized, I'm pretty sure the influence would be more C# or even JS-like. Knowing your history, helps understand your present. – Rob Mensching Jan 07 '23 at 00:39
  • @RobMensching was it influenced by BASIC, the conditions would be much easier. I had hard time understanding `Installed AND PATCH` vs (nonexisting) ``. The syntax is awkward and unnecessarily complicated. I still don't understand Installed AND PATCH and don't know if letter casing is important. Unfortunately I create office addons, so I have no option but to use this rubbish technology... – Endrju Jan 19 '23 at 11:18
8

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>
BuilderBee
  • 132
  • 1
  • 7