Wix - Conditional setting of functions based on switches

I am currently studying the WiX tool to configure MSI packages for the software applications that we have, where I work.

One of the things that I wanted to do as part of the installation was to select a specific file to install, and I will have a dialog with a list of radio buttons to allow the user to select the desired option.

Here is the WXS file I am using

<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:iis='http://schemas.microsoft.com/wix/IIsExtension'> <Product Id='E22E3B45-CFA6-4F4E-9D37-AA95A3684522' Name='Test Install' Language='1033' Version='1.0.0.0' Manufacturer='Microsoft Corporation' UpgradeCode='E22E3B45-CFA6-4F4E-9D37-AA95A3684522'> <Package Description='Test Installer Package' Comments='Install Test' Manufacturer='Microsoft Corporation' InstallerVersion='200' Compressed='yes' /> <Media Id='1' Cabinet='testinstall.cab' EmbedCab='yes' /> <Directory Id='TARGETDIR' Name='SourceDir'> <Directory Id='dir_temp' Name='Temp'> <Component Id='component_dir_root1' Guid='A51094B8-552F-49C4-9E5C-36815D471913'> <File Id='file_readme.txt' Name='readme.txt' DiskId='1' Source='root/readme.txt' /> </Component> <Component Id='component_dir_root2' Guid='A51094B8-552F-49C4-9E5C-36815D471914'> <File Id='file_readme2.txt' Name='readme2.txt' DiskId='1' Source='root/readme2.txt' /> </Component> </Directory> </Directory> <Feature Id='feature_test' Title='Test Features' Level='1'> <Feature Id='feature_dir_root1' Level='1'> <ComponentRef Id='component_dir_root1' /> <Condition Level="0"><![CDATA[RootType <> "1"]]></Condition> </Feature> <Feature Id='feature_dir_root2' Level='1'> <ComponentRef Id='component_dir_root2' /> <Condition Level="0"><![CDATA[RootType <> "2"]]></Condition> </Feature> </Feature> <UI> <Property Id="DefaultUIFont">DlgFont8</Property> <Dialog Id="InstallDlg" Width="370" Height="270" Title="[ProductName] [Setup]" NoMinimize="yes"> <Control Id="Buttons" Type="RadioButtonGroup" X="20" Y="187" Width="330" Height="40" Property="RootType" /> <Control Id="Install" Type="PushButton" X="304" Y="243" Width="56" Height="17" Default="yes" Text="Install"> <Publish Event="EndDialog" Value="Return" /> </Control> </Dialog> <RadioButtonGroup Property="RootType"> <RadioButton Text="{\DlgFont8}Root 1" Value="1" X="5" Y="0" Width="250" Height="15" /> <RadioButton Text="{\DlgFont8}Root2" Value="2" X="5" Y="20" Width="250" Height="15" /> </RadioButtonGroup> <TextStyle Id="DlgFont8" FaceName="Tahoma" Size="8" /> <InstallUISequence> <Show Dialog="InstallDlg" After="CostFinalize" /> </InstallUISequence> </UI> <Property Id="RootType">2</Property> </Product> </Wix> 

So, there are two features. Each of them corresponds to a separate component representing the files. The radio buttons refer to the RootType property, which I want to control which function is installed.

The dialog box is displayed in order, and if I change the default RootType , the correct checkbox is always displayed when the installation form is displayed. However, if during installation the user selects another radio button, it does not actually affect which file will be installed. The installed file is always the one that is set as the initial value of the RootType property.

Is there anything else that needs to be done to get the switches to update the property before the functions are set?

+2
source share
2 answers

By the time your dialogs are displayed, it is too late to set properties to affect the conditions of a function against INSTALLLEVEL. Instead, you should place control events on the next (or similar) button in the dialog box using the switches that use AddLocal or Remove to control the installation of the function.

+3
source

I had the same problem for several days. I found many examples of condition statements online, always ending with the same problem. After reading Michael Urmanโ€™s answer, I decided to find out exactly what he had in mind: โ€œInstead, you should place control events on the next (or similar) button in the dialog box using the switches that use AddLocal or Remove to control, the function is installedโ€ .

Here:

Do not put condition statements in functions. Get rid of them. Instead, check the switch values โ€‹โ€‹in the Button Control ! In your case, click Install .

Example:

  <Control Id="Install" Type="PushButton" X="304" Y="243" Width="56" Height="17" Default="yes" Text="Install"> <!--Check button values here:--> <Publish Event="AddLocal" Value="ALL">1</Publish> <Publish Event="Remove" Value="feature_dir_root1">RootType = 1</Publish> <Publish Event="Remove" Value="feature_dir_root2">RootType = 2</Publish> <Publish Event="EndDialog" Value="Return" /> </Control> 

I found an article that explains a little more about all this, as well as the AddLocal publication event. You need it, so do not delete it!

Thus, the value associated with the switches is actually checked when the Install button is clicked. This is basically.

This will actually set the function based on the switch selected by the user. Hope this helps!

+1
source

All Articles