【问题标题】:How to install features depending on the value of property如何根据财产价值安装功能
【发布时间】:2011-09-27 20:41:53
【问题描述】:

我有一个可以等于以下两个值之一的注册表项:特殊值null。和两个特点。

当我的注册表项等于特殊值时,安装程​​序必须安装第一个功能。如果注册表搜索未找到注册表项,则安装程序必须安装第二个功能。如果注册表项具有 null 值,则安装程序不得安装这两个功能中的任何一个。

我在做什么或理解错了?如果 INSTALLLEVEL=5, SPECIALVALUE="special",MYTREAT="1" 必须安装第一个功能,但在这种情况下安装程序不会同时安装这两个功能。

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

  <ComponentRef Id='Empty'/>

  <Feature Id='First' Level='3' AllowAdvertise='no' ConfigurableDirectory='INSTALLLOCATION'>
    <Condition Level="0">INSTALLLEVEL=4 OR (MYTREAT="1" AND NOT SPECIALVALUE AND NOT SPECIALVALUE="")</Condition>
    <Condition Level="1">SPECIALVALUE="special" AND MYTREAT="1"</Condition>
    <ComponentRef Id="first_comp"/>                 
  </Feature>

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

</Feature>

我已经修改了我的代码,但它仍然无法正常工作。条件有问题。注册表项中有一个特殊值,但安装程序仍在跳过第一个功能。我发现只有“MYTREAT=1”的条件不起作用。但是在日志中,客户端正在将具有此值的 MYTREAT 属性发送到服务器.. INSTALLLEVEL 为 1。 MYTREAT 属性是用按钮控件初始化的,这可能是我的麻烦吗?这里是新代码:

     <Feature Id="Myfeatures" Level="3"
            ConfigurableDirectory='INSTALLLOCATION'
            Display='expand' AllowAdvertise='no'>
                <Condition Level='1'>MYTREAT="1"</Condition>
                <ComponentRef Id='Empty'/>
                <Feature Id='First' Level='3' AllowAdvertise='no'
                    ConfigurableDirectory='INSTALLLOCATION'> <!--Must be installed by default,default value of INSTALLLEVEL is 3-->
                        <Condition Level="1">MYTREAT="1" AND SPECIALVALUE="SPECIAL"</Condition>
                        <ComponentRef Id="first_comp"/>                 
                </Feature>
                <Feature Id="Second" Level="10" AllowAdvertise="no"
                    ConfigurableDirectory="INSTALLLOCATION"><!---->
                            <Condition Level="1">(MYTREAT="1" AND NOT SPECIALVALUE)</Condition>
                            <ComponentRef Id="second_comp"/>                    
                </Feature>
        </Feature>

                     ............
<Dialog Id="TreatDlg" Width="260" Height="85">    
<Control Id="Mytreat" Type="PushButton" X="50" Y="57" Width="56" Height="17" Property="MYTREAT">
       <Publish Property="MYTREAT" Value="1">1</Publish>
       <Publish Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
    </Control>

P.S. 我默认使用 1 初始化了 MYTREAT,并且正确评估了条件。为什么我不能在功能条件下使用控件的属性?以及如何解决我的问题!请任何帮助!

【问题讨论】:

    标签: wix conditional-statements


    【解决方案1】:

    一个常见的错误是试图通过 INSTALLLEVEL 属性控制功能。安装级别应该是静态的,您不应该在安装过程中更改它。

    INSTALLLEVEL 值被视为不再安装功能的级别。例如,如果 INSTALLLEVEL = 5,将安装级别为 4 的功能,而不会安装级别为 6 的功能。

    通过INSTALLLEVEL可以控制原始特征状态,例如:

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

    对于上述配置,您可以通过设置低于或高于 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>
    

    如您所见,要素级别属性围绕 INSTALLLEVEL,而不是相反。

    编辑:

    在显示任何安装对话框之前评估功能条件。因此,您不能使用对话框控件(例如复选框或按钮)来调节功能。

    一种解决方案是使用自定义操作,该操作根据您的自定义属性修改功能操作。例如,您可以使用MsiSetFeatureState 函数。您可以在此处找到自定义操作教程: http://www.codeproject.com/KB/install/msicustomaction.aspx

    【讨论】:

    • 我很奇怪我可以用对话框控件来调节我的组件。谢谢
    • 是否已经有通过对话框更改它的解决方案? “典型的,完整的”?
    猜你喜欢
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 2012-03-12
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    相关资源
    最近更新 更多