Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the level of feature based on condition in wix?

Tags:

wix

I am trying to install the features based on the condition. Initially i set the feature level to 1 and place a condition inside the feature to modify the feature level.

I am unable to modify the feature level and it is always set to 1 only irrespective of condition.

<Feature
        Id = "AddinsFeature"
        Title  = "InstallAddin"
        Level  = "1"
        Absent="allow">
      <ComponentRef Id = "AddInComp"/>
        <Condition Level="0">
          <![CDATA[FALSE]]>
        </Condition>
</Feature>
like image 759
123r789 Avatar asked Dec 01 '25 02:12

123r789


1 Answers

This behavior changed in Wix v4: https://github.com/orgs/wixtoolset/discussions/7601

Now you must use a Level element inside of Feature: https://docs.firegiant.com/wix/schema/wxs/level/

For example, to force Level to 0 (because the Condition is always true):

<Feature Id="AddinsFeature" Title="InstallAddin" Level="1" Absent="allow">

  <!-- Force condition to be true, which sets the feature to the Level attribute value -->
  <Level Value="0" Condition="1"/>

  <ComponentRef Id = "AddInComp"/>
</Feature>

See the original answer below for more details.


How to use WiX feature conditions is essentially explained here: https://www.firegiant.com/wix/tutorial/getting-started/conditional-installation/

For a feature to be set to the level specified by your condition, the condition has to evaluate to true. You can force it to be true by setting it to 1:

<Feature Id="AddinsFeature" Title="InstallAddin" Level="1" Absent="allow">

  <!-- Force condition to be true, which sets the feature to the Level attribute value -->
  <Condition Level="0">1</Condition>

  <ComponentRef Id = "AddInComp"/>
</Feature>

Above we force the feature's install level to 0 because its condition of 1 is true (the number 1 is true in MSI logic - by definition - as in boolean). In the real world the condition would be something much more complicated - of course.

Every setup has an overall INSTALLLEVEL - and it acts as a high water mark as explained here by Chris Painter. Every feature which evaluates to a feature level below or at the INSTALLLEVEL gets installed by default.

Note: When you set the Feature level to 0 in your WiX source, the feature is not show in the setup GUI and it is not going to be installed by default either (more details in link below).

Feature manipulation can be very involved. A few links:

  • How to install feature based on the property set in custom action?

  • Unselected Feature Being Installed (over the top detailed)

  • Failing condition wix (Level=0 hides feature from GUI)

  • http://www.joyofsetup.com/2008/04/09/feature-states-in-component-conditions/

  • https://www.joyofsetup.com/2008/05/16/make-sure-features-are-always-enabled-so-they-can-be-removed/

like image 61
Stein Åsmul Avatar answered Dec 03 '25 01:12

Stein Åsmul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!