Wix Burn:注册表搜索失败时取消设置变量

Wix Burn: Unsetting variable upon failed registry search

在我的 Bundle 项目中,我正在注册表中搜索版本并设置变量:

<Variable Name="Installed_Ver" bal:Overridable="yes" Type="version" Value="0.0.0.0" Persisted="yes" />

<util:RegistrySearch
  Id="Self_Ver"
  Root="HKLM"
  Key="Software\MyCompany\MyProductName"
  Value="Version"
  Variable="Installed_Ver"  
  Format="raw"
  Win64="yes"

/>

并在条件中使用此作为:

<util:RegistrySearchRef Id="Self_Ver"  />
<bal:Condition Message="A recent or same version of this product is already installed on this machine. Please contact product support for more information." >
  <![CDATA[WixBundleInstalled OR (WixBundleFileVersion > Installed_Ver)]]>
</bal:Condition>

如果 HKLM\Software\MyCompany\MyProductName\Version 存在,这就可以正常工作。但是,如果此注册表不存在,则注册表搜索将失败,并且正在取消设置变量 'Installed_Ver'。这会导致条件错误地评估为 false。

通过定义,我尝试设置一个默认值,即“0.0.0.0”,因此它应该有一些值并且条件会被正确评估,即在这种情况下为 True。

这是日志,显示正在取消设置变量'Installed_Ver'。

[5898:2AC4][2018-08-30T13:15:08]i000: Setting string variable 'WixBundleName' to value 'RegVersionCheck' [5898:2AC4][2018-08-30T13:15:08]i000: Setting string variable 'WixBundleManufacturer' to value 'Testing' [5898:3354][2018-08-30T13:15:08]i000: Setting numeric variable 'WixStdBALanguageId' to value 1033 [5898:3354][2018-08-30T13:15:08]i000: Setting version variable 'WixBundleFileVersion' to value '7.1.2.3' [5898:2AC4][2018-08-30T13:15:08]i100: Detect begin, 1 packages [5898:2AC4][2018-08-30T13:15:08]i000: Registry key not found. Key = 'Software\MyCompany\MyProductName' [5898:2AC4][2018-08-30T13:15:08]i000: Unsetting variable 'Installed_Ver' [5898:2AC4][2018-08-30T13:15:08]i101: Detected package: MainProduct, state: Absent, cached: None [5898:2AC4][2018-08-30T13:15:08]i104: Detected package: MainProduct, feature: CalculatorFeature, state: Absent [5898:2AC4][2018-08-30T13:15:08]i052: Condition 'WixBundleInstalled OR (WixBundleFileVersion > Installed_Ver)' evaluates to false. [5898:2AC4][2018-08-30T13:15:08]e000: A recent or same version of this product is already installed on this machine. Please contact product support for more information. [5898:2AC4][2018-08-30T13:15:08]e000: Error 0x81f40001: Bundle condition evaluated to false: WixBundleInstalled OR (WixBundleFileVersion > Installed_Ver) [5898:2AC4][2018-08-30T13:15:08]i199: Detect complete, result: 0x0

我尝试在条件中用硬编码“0.0.0.0”代替 Installed_Ver,效果很好。

如果注册表搜索失败,我应该如何获取 Installed_Ver 的默认值?

谢谢

这是一个open bug。您应该能够通过更新您的条件来解决此问题,以便在未定义变量时进行处理。

WixBundleInstalled OR ((WixBundleFileVersion > Installed_Ver) AND Installed_Ver)

经过更多搜索,我找到了一些解决方法,这样我就可以使用在变量定义中设置的默认值 (0.0.0.0)。我定义了另一个搜索相同的注册表项并获取布尔(存在)变量,并根据此变量决定触发原始搜索并获取版本值。这是我的解决方案:

<Fragment Id="Self_Install_Check">

<?define ProdRegKey=Software\MyCompany\MyProductName?>
<Variable Name="Installed_Ver" bal:Overridable="yes" Type="version" Value="0.0.0.0" Persisted="yes" />

<util:RegistrySearch
  Id="Self_Ver"
  After="ProdRegExist"
  Condition="ProdRegKeyExist"
  Root="HKLM"
  Key="$(var.ProdRegKey)"
  Value="Version"
  Variable="Installed_Ver"
  Format="raw"
  Win64="yes"
/>

<util:RegistrySearch
  Id="ProdRegExist"
  Root="HKLM"
  Key="$(var.ProdRegKey)"
  Value="Version"
  Variable="ProdRegKeyExist"
  Result="exists"
  Format="raw"
  Win64="yes"
/>
</Fragment>

所以现在只有当 ProdRegKeyExist 变为真时才会触发注册表搜索阅读版本,并且 Installed_Ver 不会在保留值=0.0.0.0 时取消设置,否则将从注册表中获取版本值。 .