1

I'm trying to install a feature with the following condition: "INSTALLTHIS="YES"". The property "INSTALLTHIS" initially set "NO". Action "test_command" sets "INSTALLTHIS" too "YES". The message box in "test_command2" shows the value of this property has been set "YES". I would expect "ProductFeature" will be installed because "INSTALLTHIS="YES"" is true except it doesn’t get installed.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="*" Name="test" Language="1033" Version="1.0.0.0" Manufacturer="test_wix" UpgradeCode="351b96ea-a1af-4542-8be9-9e8e07878a99">
        <Property Id="INSTALLTHIS" Value="NO" Secure="yes"></Property>

        <Feature Id="ProductFeature" Title="SetupProject1" Level="0"> 
            <ComponentRef Id="ClientSoftware" />        
            <Condition Level="1">
                <![CDATA[INSTALLTHIS="YES"]]>
            </Condition>
        </Feature>

        <CustomAction Id="test_command" Script="vbscript">
            <![CDATA[          
                Session.Property("INSTALLTHIS") = "YES"
            ]]>
        </CustomAction>

        <CustomAction Id="test_command2" Script="vbscript">
            <![CDATA[          
                MsgBox(Session.Property("INSTALLTHIS")) <!-- SAYS YES IN THE MESSAGE BOX -->
            ]]>
        </CustomAction>

    <InstallExecuteSequence>
            <Custom Action="test_command" After="CostFinalize">NOT Installed</Custom> 
            <Custom Action="test_command2" After="test_command">NOT Installed</Custom>
    </InstallExecuteSequence>
</Product>

(I removed the unnecessary XML like the Directory settings, ComponentGroup, Component)

Michael Urman
  • 15,737
  • 2
  • 28
  • 44
Kapi
  • 547
  • 5
  • 11

2 Answers2

2

The issue you are encountering is primarily one of ordering: Feature conditions are processed during Costing (particularly during the CostFinalize action). Once Costing is complete, they have no further effect. That said, I would avoid using Feature Conditions and Levels in this manner, especially with a Level="0" involved. (Level="0" is really only safe for things that will never change, like the bitness of the operating system.)

If you want to allow your users to conditionally install a feature by passing a command line, document the features of your installer. Then they can pass ADDLOCAL=list,of,features. If instead you want to control individual components without changing the installation state of the features, you can put conditions on the components. But those are also processed during Costing, so you will still have to take care in your sequencing.

As a side note, avoid using a VBScript action merely to set a property. I assume this is a simplification of your real action, but if it is not, use a SetProperty action instead. (I'd generally recommend avoiding VBScript actions in all cases, but changing out a more complicated action has more difficulty and thus more risk, so you'll have to make that decision.)

Michael Urman
  • 15,737
  • 2
  • 28
  • 44
1

What you are looking to do is not going to be possible. Take a look at this answer to a similar question. Feature conditions are evaluated first before anything else. In your case that means that when the feature condition is evaluated INSTALLTHIS = "NO". The linked answer provides a potential solution though I have not used that approach, in an installer I work on when we needed this behavior our solution was to pass the property from the bootstrapper.

Community
  • 1
  • 1
Rick Bowerman
  • 1,866
  • 12
  • 12