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

问题描述 投票:16回答:2

我试图使简单的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>

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

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

wix installer windows-installer conditional-statements
2个回答
14
投票

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

<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>

6
投票

您是否考虑过将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>
© www.soinside.com 2019 - 2024. All rights reserved.