如何使用Wix ToolSet从网络安装.NET 6.0桌面运行时
在Wix安装项目中自动检测并安装.NET 6.0 Desktop Runtime
核心思路
Wix普通MSI项目无法直接实现网络下载操作,必须用**Burn引导程序(Bootstrapper)**完成链式安装:先检查目标机器是否已安装符合要求的.NET 6 Desktop Runtime,未安装则从官方服务器下载并静默安装,最后再部署你的应用程序。
第一步:配置运行时版本检测
通过注册表检查目标机器的.NET 6 Desktop Runtime安装状态,在Bootstrapper的Bundle配置中添加以下检测逻辑:
<!-- 检测64位系统上的.NET 6 Desktop Runtime版本 --> <Property Id="DOTNET6_DESKTOP_X64"> <RegistrySearch Id="DotNet6DesktopX64Search" Root="HKLM" Key="SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.WindowsDesktop.App" Name="Version" Type="raw" Win64="yes" /> </Property> <!-- 检测32位系统上的.NET 6 Desktop Runtime版本 --> <Property Id="DOTNET6_DESKTOP_X86"> <RegistrySearch Id="DotNet6DesktopX86Search" Root="HKLM" Key="SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x86\sharedfx\Microsoft.WindowsDesktop.App" Name="Version" Type="raw" Win64="no" /> </Property>
第二步:编写Burn引导程序配置
创建Wix Bootstrapper项目,修改Bundle.wxs文件,添加.NET 6运行时远程安装包和你的应用MSI:
<?xml version="1.0" encoding="UTF-8"?> <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension"> <Bundle Name="你的应用名称" Version="1.0.0.0" Manufacturer="你的厂商名称" UpgradeCode="替换为你的唯一GUID"> <!-- 使用Wix标准引导界面 --> <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" /> <!-- 配置64位.NET 6 Desktop Runtime远程包 --> <MsiPackage Id="Net6DesktopX64" DisplayName=".NET 6.0 Desktop Runtime (x64)" InstallCommand="/quiet /norestart" DetectCondition="DOTNET6_DESKTOP_X64 >= v6.0.0" Vital="yes" Permanent="yes" DownloadUrl="https://download.visualstudio.microsoft.com/download/pr/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/windowsdesktop-runtime-6.0.25-win-x64.exe"> <!-- 可选:添加RemotePayload验证下载文件完整性 --> <RemotePayload Size="12345678" <!-- 替换为安装包实际大小 --> Version="6.0.25" <!-- 替换为目标版本号 --> ProductName=".NET 6.0 Desktop Runtime" /> </MsiPackage> <!-- 配置32位.NET 6 Desktop Runtime远程包 --> <MsiPackage Id="Net6DesktopX86" DisplayName=".NET 6.0 Desktop Runtime (x86)" InstallCommand="/quiet /norestart" DetectCondition="DOTNET6_DESKTOP_X86 >= v6.0.0" Vital="yes" Permanent="yes" DownloadUrl="https://download.visualstudio.microsoft.com/download/pr/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/windowsdesktop-runtime-6.0.25-win-x86.exe" Condition="NOT VersionNT64"> <RemotePayload Size="87654321" Version="6.0.25" ProductName=".NET 6.0 Desktop Runtime" /> </MsiPackage> <!-- 添加你的应用程序MSI包 --> <MsiPackage Id="YourAppMsi" SourceFile="..\YourAppSetup\bin\Release\YourApp.msi" Vital="yes" /> </Bundle> </Wix>
关键参数说明
- DetectCondition:判断是否已安装符合版本要求的运行时,
>= v6.0.0确保兼容所有6.x分支的Desktop Runtime。 - InstallCommand:
/quiet /norestart实现完全静默安装,无需用户交互;若需要显示安装进度,可替换为/passive /norestart。 - DownloadUrl:从微软官方获取对应版本的运行时下载链接,确保链接为稳定的永久地址。
- RemotePayload:可选但建议添加,通过文件大小和版本号验证下载文件的完整性,避免损坏。
- Condition:针对32位/64位系统分别加载对应的运行时安装包,
VersionNT64表示当前系统为64位。
测试要点
- 在未安装.NET 6 Desktop Runtime的干净机器上测试,确认引导程序能自动下载并安装运行时。
- 测试已安装运行时的机器,确认引导程序跳过运行时安装,直接进入应用安装流程。
- 验证静默安装参数是否生效,避免弹出额外窗口干扰用户。
内容的提问来源于stack exchange,提问作者Zayd
相关产品推荐
相关产品推荐

