如何使用WiX中的功能条件?

16 installer windows-installer wix conditional-statements

我试图使简单的Windows intaller,我不知道如何处理这个.我有两个功能 - feature1和feature2.我希望仅在用户选择要安装的feature1时才安装feature2.所以我尝试过:

<Feature Id='core' Title='Core'
         Description='ØMQ 1.0.0 core functionality and C++ API' Level='1'>
  <ComponentRef Id='Core_include' />
  <ComponentRef Id='Core_bin' />
  <ComponentRef Id='Core_lib' />
  <ComponentRef Id='Core_zmq' />
  <ComponentRef Id='cpp_bin' />
</Feature>

<Feature Id='core_perf' Title='core_perf' Description='0MQ core perf' Level='999'>
    <Condition Level="0">NOT (&amp;core = "3")</Condition>
        <ComponentRef Id='cpp_perf' />
</Feature>
Run Code Online (Sandbox Code Playgroud)

但是,如果用户选择功能核心,则不会安装功能core_perf.

我怎样才能解决这个问题?

Jar*_*red 15

您需要将条件移动到组件定义中,然后使用!(功能状态)而不是&(功能操作),以便当您尝试通过第二次重新运行安装来添加示例时它可以正常工作:

<Component Id="example1">
    <Condition>!feature1 = 3</Condition>
</Component>

<Component Id="example2">
    <Condition>!feature2 = 3</Condition>
</Component>

<Feature Id="feature1">
</Feature>

<Feature Id="feature2">
</Feature>

<Feature Id="examples">
    <ComponentRef Id="example1" />
    <ComponentRef Id="example2" />
</Feature>
Run Code Online (Sandbox Code Playgroud)

  • http://msdn.microsoft.com/en-us/library/aa368012(VS.85).aspx http://www.tramontana.co.hu/wix/lesson6.php#6.2 (10认同)
  • 这记录在哪里?功能状态=!和功能动作=&. (3认同)
  • @c00000fd 这个语法是在 1997 年设计的,并且受到 BASIC 的影响,因为当时的安装空间中有很多 VB/VBScript/VBA。如果它被设计或现代化,我很确定它的影响会更多地是 C# 甚至类似 JS。了解你的历史,有助于了解你的现在。 (2认同)

Bui*_*Bee 7

您是否考虑过将feature1作为feature2的父级?除非还要安装feature1,否则无法安装feature2.没有条件.

<Feature Id='core' Title='Core' 
         Description='ØMQ 1.0.0 core functionality and C++ API' Level='1'>
    <ComponentRef Id='Core_include' />
    <ComponentRef Id='Core_bin' />
    <ComponentRef Id='Core_lib' />
    <ComponentRef Id='Core_zmq' />
    <ComponentRef Id='cpp_bin' />
    <Feature Id='core_perf' Title='core_perf' Description='0MQ core perf' 
             Level='999'>
        <ComponentRef Id='cpp_perf' />
    </Feature>
</Feature>
Run Code Online (Sandbox Code Playgroud)

  • 这种设计更符合 Windows Installer 的使用方式。 (2认同)