1
votes

It's easy in Wix to enable a component when a feature is selected. I want to do the opposite of that, where the component will be installed unless a given feature is selected. The reason is that the component performs a configuration change that is not required if the given feature is chosen.

Failed Experiments:

I've tried using conditions in the component:

<Component ...>
    <Condition>&Feature = 3</Condition>
    ...
</Component>

That doesn't work, because apparently the feature states are not calculated at the point where the component conditions are evaluated.

I've also tried using a custom action set to run before CostFinalize in order to set a property that can be tested in the Component condition. This also didn't work:

<Custom Action="Transfer_Feature_State" Before="CostFinalize" />
<Custom Action="Transfer_Feature_State_Property" Before="MtpWeb_Features_LabManager" />
<Custom Action="Transfer_Feature_State_Feature" Before="MtpWeb_Features_LabManager" />

When the custom action ran, the feature state was still set as -1, so the feature states have not been calculated before CostFinalize.

Is there any way to disable a component based on feature selection?

1
I've considered just moving my configuration change to a Custom Action that can be scheduled later, rather than using Util:XmlFile but would rather keep everything in the Wix scripts where possible.Simon Steele

1 Answers

3
votes

Components are organized into features. This means that by default all components in a feature are installed. If you don't want a feature to install a component, you can make sure that the component is not included in that feature.

What you really want is mutually exclusive features. Basically a feature which contains the component can be installed only if the other feature is not installed and the other way around.

This is not supported by Windows Installer, so it can be done only with a custom action. Basically, when the given feature is selected you can use MsiSetFeatureState function to make sure that the other feature which contains your component is not installed.