如何基于Wix捆绑包中的字符串比较编写MsiPackage/InstallCondition?
在我的WiX引导程序应用程序中,我希望根据Outlook位安装32位或64位msi包。因此,我搜索注册表值(它可以是如何基于Wix捆绑包中的字符串比较编写MsiPackage/InstallCondition?,wix,bootstrapper,Wix,Bootstrapper,在我的WiX引导程序应用程序中,我希望根据Outlook位安装32位或64位msi包。因此,我搜索注册表值(它可以是x64或x86),将其读入一个变量,并将每个MsiPackage的InstallCondition设置为该变量与相应值的字符串比较 结果出乎意料。字符串比较显然不起作用 My Bundle.wxs如下所示: <Wix ...> <Bundle ... > <util:RegistrySearchRef Id="VSTORuntimeTest" /&
x64
或x86
),将其读入一个变量,并将每个MsiPackage的InstallCondition设置为该变量与相应值的字符串比较
结果出乎意料。字符串比较显然不起作用
My 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>
它说:
InstallCondition="OLBitness ~= "x64""
及
OLBitness变量是一个“string”变量,我认为x64可能会被解析为以十六进制或其他形式表示的int??然后,当它试图将字符串转换为int时,它会错误地将其转换,因此它们永远不会匹配
您可以对此进行调试,但设置需要一段时间。当我尝试比较版本时,我不得不这样做。使用注册表搜索时,变量类型始终为字符串。wix source引擎vcproj中的condition.cpp足够智能,可以尝试将字符串变量转换为另一种类型(数值、版本),然后进行比较。结果我只是把变量名拼错了
无论如何,你也可以加上
<Variable Id="x64Bitness" Value="x64" Type="string" />
然后在安装条件下将其与x64Bitness(而不是“x64”)进行比较,这将强制进行字符串比较。可能会有所帮助,谢谢!与
“
并使用变量。顺便说一句:变量的属性是Name
,而不是Id
。与简单的=
相比,~=
的含义是什么?实际上我看不出有什么区别。~=只是比较不区分大小写的字符串。当您不控制某个字符串时,比较忽略大小写的字符串几乎总是更好的,除非您确定要考虑大小写(如CD键或某些URL)。我想这是因为您不知道Outlook的X.Y版本是否将注册表项设置为值“X64”或“X64”,如果它确实使用大写字母X,如果您不使用“~=”则无法匹配变量。这是比较级的列表,我认为这是值得再次学习本教程的。
InstallCondition="NOT (OLBitness ~= "x64")"
<Variable Id="x64Bitness" Value="x64" Type="string" />