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

使用Wix#创建MSI时,.NET SDK安装自定义动作位置咨询

Wix#中.NET SDK安装自定义动作的位置设置

你需要把安装.NET SDK的自定义动作绑定到InstallExecuteSequence里的StartServices标准动作之前,同时添加条件确保它仅在用户点击UI的「Install」按钮触发的首次安装流程中执行。具体配置如下:

核心配置要点

  • 执行时机:将自定义动作放在StartServices之前,保证服务启动前.NET SDK已完成安装
  • 触发条件:限制仅在首次安装(而非升级、修复)且是完整UI交互模式下执行
  • 动作类型:设置为同步执行、不模拟用户权限(避免权限不足),确保外部MSI安装完成后再继续流程

Wix#代码示例

var project = new ManagedProject("YourServiceInstaller",
    new Dir(@"%ProgramFiles%\YourCompany\YourService",
        new File("YourService.exe"),
        new ServiceInstaller("YourService")
        {
            Start = ServiceStartMode.Automatic,
            Description = "Your service description"
        }));

// 创建安装.NET SDK的自定义动作
var installDotNetAction = new ManagedAction("InstallDotNetSDK", 
    CustomActionSequence.InstallExecuteSequence, 
    CustomActionType.Synchronous | CustomActionType.IgnoreReturnValue | CustomActionType.NoImpersonate)
{
    Before = "StartServices",
    Condition = "NOT Installed AND UILevel >= 3" // 仅首次安装+UI交互场景触发
};

// 实现自定义动作逻辑
installDotNetAction.Execute += session =>
{
    // 静默运行.NET SDK的MSI安装包
    var processStartInfo = new ProcessStartInfo
    {
        FileName = "msiexec.exe",
        Arguments = "/i \"path/to/dotnet-sdk.msi\" /qn /norestart",
        WindowStyle = ProcessWindowStyle.Hidden,
        UseShellExecute = false,
        WaitForExit = true
    };
    using (var process = Process.Start(processStartInfo))
    {
        process.WaitForExit();
        // 可根据返回值添加日志或错误处理
    }
    return ActionResult.Success;
};

project.Actions.Add(installDotNetAction);

// 生成MSI安装包
project.BuildMsi();

关键说明

  • Condition参数解释:NOT Installed确保动作仅在首次安装时执行;UILevel >= 3对应完整UI模式,排除无人值守安装等非用户点击「Install」按钮的场景
  • 权限配置:NoImpersonate让自定义动作以系统权限运行,避免普通用户权限不足无法完成.NET SDK安装
  • 日志排查:若出现问题,可通过命令msiexec /i yourinstaller.msi /l*v install.log生成详细安装日志,查看自定义动作的执行细节

内容的提问来源于stack exchange,提问作者K.W

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 21:28:18