WiX:根据 ComboBox 选择安装组件

WiX: Install component based on ComboBox selection

我正在尝试创建一个安装程序,它根据组合框的选择来安装一些组件,但似乎条件不工作。我声明组合框如下:

...
<UI>
  <ComboBox Property="Option">
    <ListItem Text="Red" Value="red" />
    <ListItem Text="Blue" Value="blue" />
    <ListItem Text="Green" Value="green" />
  </ComboBox>
...

我有一个特点:

<Feature Id="ProductFeature" Title="MyProgram" Level="1">
  <ComponentGroupRef Id="ProductComponents" />
</Feature>

组件组声明如下:

<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
  <Component Id="MainComponent">
    <File Id="exe" Name="Main.exe" Source="Main.exe" />
  </Component>
  <Component Id="ComponentRed">
    <Condition>Option=red</Condition>
    <File Id="R" Name="config.txt" Source="red.txt" />
  </Component>
  <Component Id="ComponentBlue">
    <File Id="B" Name="config.txt" Source="blue.txt" />
    <Condition>Option=blue</Condition>
  </Component>
  <Component Id="ComponentGreen">
    <File Id="G" Name="config.txt" Source="green.txt" />
    <Condition>Option=green</Condition>
  </Component>
</ComponentGroup>

属性 需要是 public(大写)并且需要在 CDATA 中进行比较。您可以使用不区分大小写的比较 ~=.

<Component Id="ComponentRed" Guid="*" Directory="INSTALLFOLDER">
    <File Id="R" Name="red.txt" Source="red.txt" />
    <Condition>
        <![CDATA[OPTION~="Red"]]>
    </Condition>
</Component>

<Control Id="MyComboBox" Type="ComboBox" X="20" Y="140" Width="56" Height="17"
         Property="OPTION">
    <ComboBox Property="OPTION">
        <ListItem Text="Red" Value="Red" />
        <ListItem Text="Blue" Value="Blue" />
        <ListItem Text="Green" Value="Green" />
    </ComboBox>
</Control>