如何根据属性值安装功能 [英] How to install features depending on the value of property

查看:38
本文介绍了如何根据属性值安装功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注册表项,可以等于以下两个值之一:特殊值。和两个功能。



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



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

 <功能Id = MyFeatures Level = 1 ConfigurableDirectory ='INSTALLLOCATION'Display ='expand'AllowAdvertise ='no'> 

< ComponentRef Id =空 />

<功能ID ='第一'级别='3'AllowAdvertise ='否'ConfigurableDirectory ='INSTALLLOCATION'>
< Condition Level = 0> INSTALLLEVEL = 4或(MYTREAT = 1 AND NOT SPECIALVALUE AND NOT SPECIALVALUE =)< / Condition>
< Condition Level = 1> SPECIALVALUE = special AND MYTREAT = 1< / Condition>
< ComponentRef Id = first_comp />
< / 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属性是通过按钮控件初始化的,这可能是我的麻烦吗?这里是新代码:

 <功能ID = =我的功能级别= 3 
ConfigurableDirectory ='INSTALLLOCATION'
Display ='expand'AllowAdvertise ='no'>
< Condition Level ='1'> MYTREAT = 1< / Condition>
< ComponentRef Id =空 />
<功能ID ='第一'级别='3'AllowAdvertise ='否'
ConfigurableDirectory ='INSTALLLOCATION'> <!-必须默认安装,INSTALLLEVEL的默认值为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。。我默认将MYTREAT初始化为1,并且条件得到正确评估。为什么我不能在功能状态下使用控件的属性?以及如何解决我的问题!请提供任何帮助!

解决方案

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



INSTALLLEVEL值被认为是不再能够安装功能的级别。例如,如果INSTALLLEVEL = 5,将安装具有Level 4的功能,而不会安装具有Level 6的功能。



通过INSTALLLEVEL,您可以控制原始功能状态,例如:

 <功能Id = MyFeatures Level = 4 ConfigurableDirectory ='INSTALLLOCATION'Display ='expand 'AllowAdvertise ='no'> 

<!-默认情况下未安装功能->
<功能ID ='第一'级别='6'AllowAdvertise ='否'ConfigurableDirectory ='INSTALLLOCATION'/>

<!-默认情况下安装功能->
< Feature Id = Second Level = 4 AllowAdvertise = no ConfigurableDirectory = INSTALLLOCATION />

< / Feature>

对于上述配置,您可以通过将级别设置为低于或高于INSTALLLEVEL来添加安装条件:

 <功能ID = = MyFeatures Level = 4 ConfigurableDirectory ='INSTALLLOCATION'Display ='expand'AllowAdvertise ='no '> 

<功能ID ='第一'级别='6'AllowAdvertise ='否'ConfigurableDirectory ='INSTALLLOCATION'>
< Condition Level = 4>(MYTREAT = 1)AND(SPECIALVALUE = special)< / Condition>
< / Feature>

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

< / Feature>

如您所见,要素的Level属性围绕INSTALLLEVEL展开,而不是相反。 p>

编辑:



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



一种解决方案是使用自定义操作,该操作会根据在您的自定义媒体资源上。例如,您可以使用 MsiSetFeatureState 函数。您可以在此处找到自定义操作教程:
http://www.codeproject.com/KB/install /msicustomaction.aspx


I have a registry key that can be equal to one of two values: special value or null. And two features.

When my registry key equals to special value the installer has to install first feature. if registry key is not found by registry search the installer has to install second feature. And if registry key has null value the installer must not install any of these two features.

What I'm doing or understanding wrong? If INSTALLLEVEL=5, SPECIALVALUE="special",MYTREAT="1" the first feature must be installed,but the installer doesn't install both of the features in this case.

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

I had modified my code, but it's still not working right. Problem with conditions. There is a special value in registry key, but the installer is still skipping first feature. I had found that condition with just "MYTREAT=1" is not working. But in logs the client side is sending MYTREAT property with this value to the server.. INSTALLLEVEL is 1. MYTREAT property is initialized with pushbutton control,may be here is my trouble? Here new code:

     <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. I initialized MYTREAT with 1 by default and condition was evaluated correctly. Why I cannot use control's property in feature's condition? And how to resolve my problem!Please any help!

解决方案

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

这篇关于如何根据属性值安装功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆