How to install features depending on the value of property

南楼画角 提交于 2019-11-29 10:41:56

A common mistake is trying to control features through INSTALLLEVEL property. The install level should be static, you shouldn't change it during install.

The INSTALLLEVEL value is considered a level above which features are no longer installed. For example, if INSTALLLEVEL = 5 a feature with Level 4 will be installed and a feature with Level 6 will not be installed.

Through INSTALLLEVEL you can control the original feature state, for example:

<Feature Id="MyFeatures" Level="4" ConfigurableDirectory='INSTALLLOCATION' Display='expand' AllowAdvertise='no'>

  <!-- Feature is not installed by default -->
  <Feature Id='First' Level='6' AllowAdvertise='no' ConfigurableDirectory='INSTALLLOCATION'/>

  <!-- Feature is installed by default -->
  <Feature Id="Second" Level="4" AllowAdvertise="no" ConfigurableDirectory="INSTALLLOCATION"/>    

</Feature>

For the above configuration you can then add install conditions by setting a Level lower or higher than INSTALLLEVEL:

<Feature Id="MyFeatures" Level="4" ConfigurableDirectory='INSTALLLOCATION' Display='expand' AllowAdvertise='no'>

  <Feature Id='First' Level='6' AllowAdvertise='no' ConfigurableDirectory='INSTALLLOCATION'>
    <Condition Level="4">(MYTREAT="1") AND (SPECIALVALUE="special")</Condition>         
  </Feature>

  <Feature Id="Second" Level="4" AllowAdvertise="no" ConfigurableDirectory="INSTALLLOCATION">
    <Condition Level="6">(INSTALLLEVEL = 3) OR (MYTREAT="1" AND SPECIALVALUE)</Condition>
  </Feature>

</Feature>

As you can see, the feature Level attributes revolve around INSTALLLEVEL, not the other way around.

Edit:

Feature conditions are evaluated before any installation dialogs are shown. So you cannot condition a feature with a dialog control (for example a checkbox or a button).

A solution would be to use a custom action which modifies the feature action based on your custom property. For example you can use MsiSetFeatureState function. You can find a custom action tutorial here: http://www.codeproject.com/KB/install/msicustomaction.aspx

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