2011-09-26 43 views
4

我有一個註冊表項可以等於兩個值之一:特殊值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.默認情況下,我初始化了MYTREAT 1,條件被正確評估。爲什麼我無法在功能條件下使用控件的屬性?以及如何解決我的問題!請任何幫助!

回答

7

一個常見的錯誤是試圖通過INSTALLLEVEL屬性來控制功能。安裝級別應該是靜態的,在安裝過程中不應更改它。

INSTALLLEVEL值被認爲是高於此值的功能不再安裝。例如,如果INSTALLLEVEL = 5,則將安裝Level 4的功能,並且不會安裝Level 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

+1

很奇怪,我認爲我可以調節我的部件一個對話框控制。謝謝 – Nerielle

+0

是否有已經通過對話框來改變它的解決方案? 「典型,完整」? –

相關問題