How to use conditions in features in WiX?

夙愿已清 提交于 2019-11-29 02:26:37

问题


I am trying to make simple Windows intaller, and I don't know how to deal with this. I have two features - feature1 and feature2. I want feature2 to be installed only if the user selected feature1 to be installed. So I tried:

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

But this doesn't install feature core_perf if the user selects feature core.

How can I fix this?


回答1:


You need to move your Condition into your Component definition, and use ! (Feature state) instead of & (Feature action) so that it works when you try to add the examples by re-running the install a second time:

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



回答2:


Have you considered making feature1 the parent of feature2? Then feature2 can't be installed unless feature1 will also be installed. No condition necessary.

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


来源:https://stackoverflow.com/questions/1158565/how-to-use-conditions-in-features-in-wix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!