2016-04-22 33 views
3

在我的WiX Bootstrapper應用程序中,我想根據Outlook位安裝32位或64位MsiPackage。因此,我搜索註冊表值(它可以是x64x86),將其讀入一個變量,並將每個MsiPackage的InstallCondition設置爲該變量與適當值的字符串比較。如何根據Wix包中的字符串比較來編寫MsiPackage/InstallCondition?

結果並非意外。字符串比較顯然不起作用。

我Bundle.wxs看起來是這樣的:

<Wix ...> 
<Bundle ... > 
    <util:RegistrySearchRef Id="VSTORuntimeTest" /> 
    <util:RegistrySearchRef Id="VSTORuntimeVersionV4R" /> 
    <util:RegistrySearchRef Id="VSTORuntimeVersionV4" /> 

    <util:RegistrySearchRef Id="Outlook14Installed"/> 
    <util:RegistrySearchRef Id="Outlook15Installed"/> 
    <util:RegistrySearchRef Id="Outlook16Installed"/> 
    <util:RegistrySearchRef Id="Outlook14Bitness"/> 
    <util:RegistrySearchRef Id="Outlook15Bitness"/> 
    <util:RegistrySearchRef Id="Outlook16Bitness"/> 

    <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense"> 
    <bal:WixStandardBootstrapperApplication ... /> 
    </BootstrapperApplicationRef> 
    <Variable Name="InstallSubFolder" 
      Type="string" 
      Value="$(var.CompanyFolderName)\$(var.ProductFolderName)" /> 

    <Chain> 
    <PackageGroupRef Id="NetFx40Web"/> 

    <ExePackage Id="VSTORuntime" SourceFile="$(var.SolutionDir)\WiX\vstor_redist.exe" Permanent="yes" Vital="yes" Cache="no" Compressed="no" 
     DownloadUrl="http://go.microsoft.com/fwlink/?LinkId=158917" 
     PerMachine="yes" 
     InstallCommand="/q /norestart" 
     DetectCondition="VSTORFeature" 
     InstallCondition="NOT VSTORFeature OR NOT (VSTORVersionV4R >=v10.0.40303) OR NOT (VSTORVersionV4 >=v10.0.21022)" /> 

    <MsiPackage 
     Id="OLAddin64bit" 
     Vital="yes" 
     Name="$(var.ProductName) 64 bit" 
     SourceFile="$(var.Setup_64bit_WiX.TargetPath)" 
     InstallCondition="OLBitness = x64"> 
     <MsiProperty Name="INSTALLLOCATION" Value="[ProgramFiles64Folder][InstallSubFolder]"/> 
    </MsiPackage> 

    <MsiPackage 
     Id="OLAddin32bit" 
     Vital="yes" 
     Name="$(var.ProductName) 32 bit" 
     SourceFile="$(var.Setup_32bit_WiX.TargetPath)" 
     InstallCondition="NOT (OLBitness = x64)"> 
     <MsiProperty Name="INSTALLLOCATION" Value="[ProgramFilesFolder][InstallSubFolder]"/> 
    </MsiPackage> 
    </Chain> 
</Bundle> 

<Fragment> 
    <util:RegistrySearch Id="VSTORuntimeTest" Root="HKLM" Key="SOFTWARE\Microsoft\VSTO Runtime Setup\v4R\" Value="VSTORFeature_CLR40" Variable="VSTORFeature"/> 
    <util:RegistrySearch Id="VSTORuntimeVersionV4R" Root="HKLM" Key="SOFTWARE\Microsoft\VSTO Runtime Setup\v4R\" Value="Version" Variable="VSTORVersionV4R"/> 
    <util:RegistrySearch Id="VSTORuntimeVersionV4" Root="HKLM" Key="SOFTWARE\Microsoft\VSTO Runtime Setup\v4\" Value="Version" Variable="VSTORVersionV4"/> 

    <util:RegistrySearch Id="Outlook14Installed" Root="HKLM" Key="SOFTWARE\Microsoft\Office\14.0\Outlook\InstallRoot\"       Variable="Outlook14Installed" Result="exists" Win64="yes"/> 
    <util:RegistrySearch Id="Outlook15Installed" After="Outlook14Installed" Root="HKLM" Key="SOFTWARE\Microsoft\Office\15.0\Outlook\InstallRoot\" Variable="Outlook15Installed" Result="exists" Win64="yes" /> 
    <util:RegistrySearch Id="Outlook16Installed" After="Outlook15Installed" Root="HKLM" Key="SOFTWARE\Microsoft\Office\16.0\Outlook\InstallRoot\" Variable="Outlook16Installed" Result="exists" Win64="yes" /> 

    <util:RegistrySearch Id="Outlook14Bitness" Condition="Outlook14Installed" Variable="OLBitness" After="Outlook16Installed" Root="HKLM" Key="SOFTWARE\Microsoft\Office\15.0\Outlook\" Value="Bitness" Win64="yes" /> 
    <util:RegistrySearch Id="Outlook15Bitness" Condition="Outlook15Installed" Variable="OLBitness" After="Outlook16Installed" Root="HKLM" Key="SOFTWARE\Microsoft\Office\15.0\Outlook\" Value="Bitness" Win64="yes" /> 
    <util:RegistrySearch Id="Outlook16Bitness" Condition="Outlook16Installed" Variable="OLBitness" After="Outlook16Installed" Root="HKLM" Key="SOFTWARE\Microsoft\Office\16.0\Outlook\" Value="Bitness" Win64="yes" /> 

    <bal:Condition 
    Message="Outlook 2010 or newer required."> 
    Outlook14Installed Or Outlook15Installed or Outlook16Installed 
    </bal:Condition> 
</Fragment> 

</Wix> 

現在的安裝程序寫入以下日誌:

[5FBC:FE84][2016-04-22T16:30:05]i001: Burn v3.10.1.2213, Windows v6.3 (Build 9600: Service Pack 0), path: Setup.exe 
[5FBC:FE84][2016-04-22T16:30:05]i000: Initializing string variable 'InstallSubFolder' to value 'foo' 
[5FBC:FE84][2016-04-22T16:30:05]i009: Command Line: '' 
... 
[5FBC:FE84][2016-04-22T16:30:05]i100: Detect begin, 4 packages 
[5FBC:FE84][2016-04-22T16:30:05]i000: Setting string variable 'NETFRAMEWORK40' to value '1' 
[5FBC:FE84][2016-04-22T16:30:05]i000: Registry key not found. Key = 'SOFTWARE\Microsoft\Office\14.0\Outlook\InstallRoot\' 
[5FBC:FE84][2016-04-22T16:30:05]i000: Setting numeric variable 'Outlook14Installed' to value 0 
[5FBC:FE84][2016-04-22T16:30:05]i000: Registry key not found. Key = 'SOFTWARE\Microsoft\Office\15.0\Outlook\InstallRoot\' 
[5FBC:FE84][2016-04-22T16:30:05]i000: Setting numeric variable 'Outlook15Installed' to value 0 
[5FBC:FE84][2016-04-22T16:30:05]i000: Setting numeric variable 'Outlook16Installed' to value 1 
[5FBC:FE84][2016-04-22T16:30:05]i052: Condition 'Outlook14Installed' evaluates to false. 
[5FBC:FE84][2016-04-22T16:30:05]i052: Condition 'Outlook15Installed' evaluates to false. 
[5FBC:FE84][2016-04-22T16:30:05]i052: Condition 'Outlook16Installed' evaluates to true. 
[5FBC:FE84][2016-04-22T16:30:05]i000: Setting string variable 'OLBitness' to value 'x64' 
[5FBC:FE84][2016-04-22T16:30:05]i000: Setting string variable 'VSTORFeature' to value '1' 
[5FBC:FE84][2016-04-22T16:30:05]i000: Setting string variable 'VSTORVersionV4' to value '10.0.60301' 
[5FBC:FE84][2016-04-22T16:30:05]i000: Setting string variable 'VSTORVersionV4R' to value '10.0.50903' 
[5FBC:FE84][2016-04-22T16:30:05]i052: Condition 'NETFRAMEWORK40' evaluates to true. 
[5FBC:FE84][2016-04-22T16:30:05]i052: Condition 'VSTORFeature' evaluates to true. 
[5FBC:FE84][2016-04-22T16:30:05]i101: Detected package: NetFx40Web, state: Present, cached: None 
[5FBC:FE84][2016-04-22T16:30:05]i101: Detected package: VSTORuntime, state: Present, cached: None 
[5FBC:FE84][2016-04-22T16:30:05]i101: Detected package: Addin64bit, state: Absent, cached: None 
[5FBC:FE84][2016-04-22T16:30:05]i101: Detected package: Addin32bit, state: Absent, cached: None 
[5FBC:FE84][2016-04-22T16:30:05]i052: Condition 'Outlook14Installed Or Outlook15Installed or Outlook16Installed' evaluates to true. 
[5FBC:FE84][2016-04-22T16:30:05]i199: Detect complete, result: 0x0 
[5FBC:10EE4][2016-04-22T16:30:07]i000: Setting numeric variable 'EulaAcceptCheckbox' to value 1 
[5FBC:FE84][2016-04-22T16:30:07]i200: Plan begin, 4 packages, action: Install 
[5FBC:FE84][2016-04-22T16:30:07]w321: Skipping dependency registration on package with no dependency providers: NetFx40Web 
[5FBC:FE84][2016-04-22T16:30:07]i052: Condition 'NOT VSTORFeature OR NOT (VSTORVersionV4R >=v10.0.40303) OR NOT (VSTORVersionV4 >=v10.0.21022)' evaluates to false. 
[5FBC:FE84][2016-04-22T16:30:07]w321: Skipping dependency registration on package with no dependency providers: VSTORuntime 
[5FBC:FE84][2016-04-22T16:30:07]i052: Condition 'OLBitness=x64' evaluates to false. 
[5FBC:FE84][2016-04-22T16:30:07]i052: Condition 'NOT (OLBitness=x64)' evaluates to true. 
[5FBC:FE84][2016-04-22T16:30:07]i000: Setting string variable 'WixBundleRollbackLog_Addin32bit' to value 'foo.log' 
[5FBC:FE84][2016-04-22T16:30:07]i000: Setting string variable 'WixBundleLog_OLPlannerAddin32bit' to value 'foo.log' 
[5FBC:FE84][2016-04-22T16:30:07]i201: Planned package: NetFx40Web, state: Present, default requested: Present, ba requested: Present, execute: None, rollback: None, cache: No, uncache: No, dependency: None 
[5FBC:FE84][2016-04-22T16:30:07]i201: Planned package: VSTORuntime, state: Present, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None 
[5FBC:FE84][2016-04-22T16:30:07]i201: Planned package: Addin64bit, state: Absent, default requested: Absent, ba requested: Absent, execute: None, rollback: None, cache: No, uncache: No, dependency: None 
[5FBC:FE84][2016-04-22T16:30:07]i201: Planned package: Addin32bit, state: Absent, default requested: Present, ba requested: Present, execute: Install, rollback: Uninstall, cache: Yes, uncache: No, dependency: Register 
[5FBC:FE84][2016-04-22T16:30:07]i299: Plan complete, result: 0x0 
[5FBC:FE84][2016-04-22T16:30:07]i300: Apply begin 
[5FBC:FE84][2016-04-22T16:30:07]i010: Launching elevated engine process. 
... 
[5FBC:FE84][2016-04-22T16:30:15]i399: Apply complete, result: 0x80070642, restart: None, ba requested restart: No 
[5FBC:FE84][2016-04-22T16:30:16]i500: Shutting down, exit code: 0x642 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: EulaAcceptCheckbox = 1 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: InstallSubFolder = foo 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: NETFRAMEWORK40 = 1 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: OLBitness = x64 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: Outlook14Installed = 0 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: Outlook15Installed = 0 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: Outlook16Installed = 1 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: VSTORFeature = 1 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: VSTORVersionV4 = 10.0.60301 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: VSTORVersionV4R = 10.0.50903 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: WixBundleAction = 5 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: WixBundleElevated = 0 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: WixBundleFileVersion = 1.0.0.0 
[5FBC:FE84][2016-04-22T16:30:16]i410: Variable: WixBundleInstalled = 0 
... 
[5FBC:FE84][2016-04-22T16:30:16]i007: Exit code: 0x642, restarting: No 

它指出:

  1. 設置字符串變量 'OLBitness' 來值'x64'
  2. 條件'OLBitness = x64'的計算結果爲false
  3. 變量:OLBitness = 64

評估爲什麼要在預計虛假情況而值似乎很明顯?

如何編寫InstallCondition來測試字符串的相等性?

我可以使用一個屬性,如果是的話,我會怎麼做?

我找到了RegistrySearches的例子,Result =「exists」但沒有Result =「value」。

感謝您的任何提示!

+0

http://stackoverflow.com/questions/6231950/using-wix-to-create-32bit-and-64bit-installers-from-one-wxs-file可能會幫助 – ChrisBint

回答

1

嘗試

InstallCondition="OLBitness ~= &quot;x64&quot;" 

InstallCondition="NOT (OLBitness ~= &quot;x64&quot;)" 

的OLBitness變量是「字符串」變量,我認爲64可能會被解析爲十六進制或東西代表的INT回升? ?然後,當它試圖將字符串轉換爲int時,它會將其轉換爲非常錯誤,因此它們永遠不會匹配。

您可以調試,但需要一段時間才能設置。當我試圖比較版本時,我必須這樣做。當您使用註冊表搜索時,變量類型始終是字符串。來自wix源的引擎vcproj中的condition.cpp足夠智能,可以嘗試將字符串變量轉換爲另一種類型(數字,版本),然後進行比較。而事實證明,我剛剛拼錯變量不管怎麼說命名錯誤......

,你還可以添加

<Variable Id="x64Bitness" Value="x64" Type="string" /> 

你的包,然後在安裝條件比較它x64Bitness而不是「 x64「,這將強制字符串比較。

+0

非常感謝!比較適用於'"'和變量。順便說一句註釋:變量具有屬性'Name'而不是'Id'。與簡單的'='相比,'〜='的含義是什麼?實際上我沒有看到任何區別。 –

+0

〜=只是比較字符串不區分大小寫。比較字符串幾乎總是比較好,因爲除非您確定要考慮事件(如CD鍵或某些URL),否則在不控制其中一個字符串的情況下忽略該情況。我想這個想法是你不確定Outlook的XY版本是否將註冊表鍵值設置爲值「X64」或「x64」,並且如果它使用大寫字母X,如果不使用「〜 =「你不會匹配變量。這裏是比較列表https://www.firegiant.com/wix/tutorial/com-expression-syntax-miscellanea/expression-syntax/ –

+1

我發現它值得再次通過教程。 –