You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Bootstrapper的ExePackage DetectCondition中使用CustomAction检测.NET Core安装状态

问题分析与解决

直接错误原因

  1. CustomAction的BinaryKey拼写错误:代码里BinaryKey=".CustomAction.dll"多了一个前缀点,正确应为BinaryKey="CustomAction.dll",这会导致Wix找不到自定义动作的DLL,无法执行TestMethod,也就不会设置ASPDOTNETCORE60变量。
  2. 无效的WixVariable定义:<WixVariable Id="ASPDOTNETCORE60" Value="[ASPDOTNETCORE60]" />是循环引用,无实际意义,应删除。
  3. 上下文不匹配:即使修正前两个问题,Burn的ExePackage的DetectCondition也无法读取MSI CustomAction设置的session变量——两者属于不同执行上下文(Burn是Bootstrapper层面,MSI是子安装包层面),变量不共享。

正确实现方式

方案一:用RegistrySearch检测(推荐,无需自定义代码)

.NET Core Hosting Bundle安装后会在注册表留下版本记录,直接通过注册表搜索即可完成检测,无需编写CustomAction:

<Fragment>
    <!-- 定义存储检测结果的变量 -->
    <VariableGroup Id="NetCoreDetection">
        <Variable Name="ASPDOTNETCORE60" Type="numeric" Value="0" />
    </VariableGroup>

    <!-- 搜索.NET Core 6.0.8 Hosting Bundle的注册表项 -->
    <util:RegistrySearch
        Id="CheckAspNetCore60"
        Root="HKLM"
        Key="SOFTWARE\Microsoft\AspNetCore\Shared Framework\v6.0"
        Value="6.0.8"
        Variable="ASPDOTNETCORE60"
        Result="exists"
        Win64="yes" />

    <PackageGroup Id="NetRuntime6Web">
        <ExePackage
            Name="dotnet-hosting-6.0.8-win.exe"
            InstallCommand="/install /quiet /norestart /log &quot;[AspNetCoreRuntime6Log]&quot;"
            RepairCommand="/repair /quiet /norestart /log &quot;[AspNetCoreRuntime6Log]&quot;"
            UninstallCommand="/uninstall /quiet /norestart /log &quot;[AspNetCoreRuntime6Log]&quot;"
            PerMachine="yes"
            DetectCondition="ASPDOTNETCORE60 = 1"
            Vital="yes"
            Permanent="yes"
            Protocol="burn"
            DownloadUrl="https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.8-windows-hosting-bundle-installer"
            LogPathVariable="AspNetCoreRuntime6Log"
            SourceFile="C:\Net\dotnet-hosting-6.0.8-win.exe"
            Compressed="yes">
        </ExePackage>
    </PackageGroup>
</Fragment>

方案二:用Burn自定义动作(若需复杂检测逻辑)

如果需要更灵活的检测规则(如多版本兼容判断),可以编写独立的检测程序,通过Burn的ExePackage返回码判断:

  1. 编写控制台程序,实现.NET Core版本检测逻辑:已安装目标版本返回0,未安装返回1。
  2. 在Bundle中添加该检测程序包:
<Fragment>
    <PackageGroup Id="NetRuntime6Web">
        <!-- 检测程序包,仅用于判断是否已安装 -->
        <ExePackage
            Id="CheckNetCore6"
            SourceFile="你的检测程序路径.exe"
            InstallCommand="check"
            DetectCondition="CheckNetCore6ReturnCode = 0"
            Vital="no"
            Permanent="yes"
            Compressed="yes" />

        <!-- 原有的Hosting Bundle安装包 -->
        <ExePackage
            Name="dotnet-hosting-6.0.8-win.exe"
            InstallCommand="/install /quiet /norestart /log &quot;[AspNetCoreRuntime6Log]&quot;"
            RepairCommand="/repair /quiet /norestart /log &quot;[AspNetCoreRuntime6Log]&quot;"
            UninstallCommand="/uninstall /quiet /norestart /log &quot;[AspNetCoreRuntime6Log]&quot;"
            PerMachine="yes"
            DetectCondition="CheckNetCore6ReturnCode = 0"
            Vital="yes"
            Permanent="yes"
            Protocol="burn"
            DownloadUrl="https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.8-windows-hosting-bundle-installer"
            LogPathVariable="AspNetCoreRuntime6Log"
            SourceFile="C:\Net\dotnet-hosting-6.0.8-win.exe"
            Compressed="yes">
        </ExePackage>
    </PackageGroup>
</Fragment>

内容的提问来源于stack exchange,提问作者Ehsan Ghorabian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 12:45:35