如果已安装,请跳过 MSI

Skip MSI if already installed

我有一个 WIX 安装程序,我在其中安装了我的程序和 .NET Core 1.0.5。 .NET Core 以静默模式安装:

<ExePackage InstallCommand="/q" Id = "DotNetCore.Setup" SourceFile="..\DotNetCore\DotNetCore.exe" />

在干净的系统上,安装程序运行良好。如果我尝试重新安装它,我会重新启动。可能是 .NET 安装程序检测到已安装并自行触发了修复功能。如果已经安装了 .NET Core,是否有任何方法可以跳过它的安装?

我尝试寻找命令行参数,但似乎没什么用

如果安装了 .net Core,您需要使用分配 属性 的 DetectCondition 属性和注册表搜索。

ExePackage Element - DetectCondition

"A condition that determines if the package is present on the target system. This condition can use built-in variables and variables returned by searches. This condition is necessary because Windows doesn't provide a method to detect the presence of an ExePackage. Burn uses this condition to determine how to treat this package during a bundle action; for example, if this condition is false or omitted and the bundle is being installed, Burn will install this package."

ExePackage 元素具有 DetectCondition 属性。这意味着您可以指定一个条件,如果该条件的计算结果为假,则将安装该包。您可以将其与 util:RegistrySearch 元素结合使用,该元素可用于搜索注册表以检测是否已安装 .NET Core。

为了执行注册表搜索,您首先需要找到安装 .NET 时存在的注册表项。

找到 "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\", (或 "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" 在 64 位机器上)注册表中的键,然后找到对应于 .NET Core 的子键 - 这个键应该有一个 "DisplayName" 的值,它应该是“.NET Core”或类似的东西。

一旦找到正确的密钥,其名称应该是一串十六进制字符 - 这是对应于 .NET Core 程序的 GUID 之一。然后您可以使用以下代码让安装程序搜索是否存在此密钥:

<util:RegistrySearch Id="VCRedistTest32" Root="HKLM" Key="SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{YOUR_GUID_HERE}" Result="exists" Variable="DOTNETPresent" Win64="no"/>

(使用 Win64="yes" 而不是 64 位注册表)

然后您可以将以下内容用于 ExePackage:

<ExePackage InstallCommand="/q" Id = "DotNetCore.Setup" SourceFile="..\DotNetCore\DotNetCore.exe" DetectCondition="DOTNETPresent"/>

不要忘记将对 util 扩展的引用添加到顶级 wix 元素:

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
 xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">