如何通过WIX卸载Bundle中的.NET 8 Runtime与ASP.NET Core?
解决Wix Bundle无法自动卸载.NET 8组件的问题
问题核心在于你的ExePackage缺少检测条件配置,Wix无法识别.NET组件是否已安装,因此卸载流程中不会触发对应的卸载命令。手动执行卸载命令有效,说明卸载参数本身没问题,只需让Wix正确关联组件的安装状态。
解决方案步骤:
1. 添加注册表检测逻辑
通过Wix的UtilExtension提供的RegistrySearch,检测.NET Runtime和ASP.NET Core的注册表项(这是.NET安装后自动写入的标识),确认组件是否已安装。
2. 为ExePackage配置检测条件
将注册表检测的结果关联到对应ExePackage的DetectCondition属性,同时设置PerMachine="yes"(符合.NET运行时的全局安装特性)。
修改后的完整Bundle.wxs代码:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"> <?include APIVariables.wxi ?> <Bundle Name="$(var.ProductName)" Version="$(var.InstallerVersion)" Manufacturer="$(var.CompanyName)" UpgradeCode="$(var.APIUpgradeCode)" Copyright="$(var.CopyrightStatement)"> <!-- 检测.NET 8.0.6 Runtime是否已安装 --> <util:RegistrySearch Id="DetectDotNetRuntime806" Root="HKLM" Key="SOFTWARE\Microsoft\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.NETCore.App\8.0.6" Value="Version" Result="exists" Variable="DotNetRuntime806Installed" /> <!-- 检测ASP.NET Core 8.0.6 Runtime是否已安装 --> <util:RegistrySearch Id="DetectAspNetCoreRuntime806" Root="HKLM" Key="SOFTWARE\Microsoft\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.AspNetCore.App\8.0.6" Value="Version" Result="exists" Variable="AspNetCoreRuntime806Installed" /> <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLargeLicense" > <bal:WixStandardBootstrapperApplication ShowVersion="yes" /> </BootstrapperApplicationRef> <Chain> <ExePackage Name="vcredist_x64_14.29.30139.exe" SourceFile="vcredist_x64_14.29.30139.exe" InstallCommand="/install /quiet /norestart" UninstallCommand="/uninstall /quiet /norestart" Vital="yes" /> <ExePackage Name="dotnet-runtime-8.0.6-win-x64.exe" SourceFile="dotnet-runtime-8.0.6-win-x64.exe" InstallCommand="/install /quiet /norestart" UninstallCommand="/uninstall /quiet /norestart" Vital="yes" DetectCondition="DotNetRuntime806Installed" PerMachine="yes" /> <ExePackage Name="aspnetcore-runtime-8.0.6-win-x64.exe" SourceFile="aspnetcore-runtime-8.0.6-win-x64.exe" InstallCommand="/install /quiet /norestart" UninstallCommand="/uninstall /quiet /norestart" Vital="yes" DetectCondition="AspNetCoreRuntime806Installed" PerMachine="yes" /> <MsiPackage Name="RabbitMQ.Installer.msi" SourceFile="$(var.RabbitMQ.Installer.TargetDir)RabbitMQ.Installer.msi" Vital="yes" Visible="no" Cache="no" /> <MsiPackage Name="WAA.API.msi" SourceFile="$(var.WAA.API.InstallModule.TargetDir)WAA.API.msi" Vital="yes" Visible="no" Cache="no" /> </Chain> </Bundle> </Wix>
关键说明:
RegistrySearch通过检查HKLM下的.NET安装注册表项,设置变量标识组件是否存在。DetectCondition让Wix在卸载时判断:如果该组件已安装,则执行对应的UninstallCommand。PerMachine="yes"确保Wix按机器全局维度处理组件的安装/卸载,匹配.NET运行时的安装模式。
内容的提问来源于stack exchange,提问作者Błażej
相关产品推荐
相关产品推荐

