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

WiX Toolset v4自定义Managed Bootstrapper应用创建失败(错误0x80131524)

解决WiX Toolset v4自定义Managed Bootstrapper Application创建失败错误(0x80131524)

问题背景

在WiX Toolset v4中创建带自定义Managed Bootstrapper Application(MBA)的安装程序,参考WiX v3教程适配后,运行安装程序时出现错误0x80131524,提示创建引导程序应用失败。

已完成的适配操作

  • 在CustomBootstrapperApplication项目中,将引用从Microsoft.Tools.WindowsInstallerXml.Bootstrapper改为WixToolset.Mba.Core
  • 添加CustomUI.Factory.cs文件:
[assembly: WixToolset.Mba.Core.BootstrapperApplicationFactory(typeof(CustomBootstrapperApplication.CustomUIFactory))]
namespace CustomBootstrapperApplication
{
    using WixToolset.Mba.Core;

    public class CustomUIFactory : BaseBootstrapperApplicationFactory
    {
        protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand command)
        {
            return new CustomUI(engine);
        }
    }
}
  • 修改CustomUI.cs:
using System;
using System.Windows.Threading;
using WixToolset.Mba.Core;

namespace CustomBootstrapperApplication
{
    public class CustomUI : BootstrapperApplication
    {
        public CustomUI(IEngine engine) : base(engine)
        {
        }

        public IEngine Engine => this.engine;

        public static Dispatcher BootstrapperDispatcher { get; private set; }

        protected override void Run()
        {
            this.Engine.Log(LogLevel.Verbose, "Launching Custom UI");
            BootstrapperDispatcher = Dispatcher.CurrentDispatcher;

            MainWindow view = new MainWindow(this);
            view.Bootstrapper.Engine.Detect();
            view.DataContext = view;
            view.Closed += (sender, e) => BootstrapperDispatcher.InvokeShutdown();
            view.Show();

            Dispatcher.Run();
            this.Engine.Quit(0);
        }
    }
}
  • 将配置文件重命名为WixToolset.Mba.Host.config并适配内容:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <sectionGroup name="wix.bootstrapper" type="WixToolset.Mba.Host.BootstrapperSectionGroup, WixToolset.Mba.Host">
      <section name="host" type="WixToolset.Mba.Host.HostSection, WixToolset.Mba.Host" />
    </sectionGroup>
  </configSections>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
  </startup>
  <wix.bootstrapper>
    <host assemblyName="CustomBootstrapperApplication">
    </host>
  </wix.bootstrapper>
</configuration>
  • 修改MainWindow.xaml.cs,用CustomUI替代原BootstrapperApplication类型:
using System;
using System.Windows;
using WixToolset.Mba.Core;

namespace CustomBootstrapperApplication
{
    public partial class MainWindow : Window
    {
        private bool isInstall;

        public MainWindow(CustomUI bootstrapper)
        {
            InitializeComponent();
            this.Bootstrapper = bootstrapper;
            this.Bootstrapper.DetectPackageComplete += this.OnDetectPackageComplete;
            this.Bootstrapper.PlanComplete += this.OnPlanComplete;
            this.Bootstrapper.ExecuteProgress += this.OnExecuteProgress;
            this.Bootstrapper.ExecuteComplete += this.OnExecuteComplete;
            this.Bootstrapper.ExecuteBegin += this.OnExecuteBegin;
        }
        public CustomUI Bootstrapper { get; private set; }

        private void Exit_Button_Click(object sender, RoutedEventArgs e)
        {
            CustomUI.BootstrapperDispatcher.InvokeShutdown();
        }

        private void Install_Button_Click(object sender, RoutedEventArgs e)
        {
            isInstall = true;
            Install_Button.Visibility = Visibility.Collapsed;
            process.Content = "Waiting to Install...";
            Bootstrapper.Engine.Plan(LaunchAction.Install);
        }

        private void Uninstall_Button_Click(object sender, RoutedEventArgs e)
        {
            isInstall = false;
            Uninstall_Button.Visibility = Visibility.Collapsed;
            process.Content = "Waiting to Uninstall...";
            Bootstrapper.Engine.Plan(LaunchAction.Uninstall);
        }

        private void OnExecuteComplete(object sender, ExecuteCompleteEventArgs e)
        {
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                      delegate ()
                      {
                          process.Content = isInstall ? "Installed" : "Uninstalled";
                      }));
        }
        private void OnExecuteBegin(object sender, ExecuteBeginEventArgs e)
        {
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                      delegate ()
                      {
                          process.Content = isInstall ? "Installing..." : "Uninstalling...";
                      }));
        }

        private void OnDetectPackageComplete(object sender, DetectPackageCompleteEventArgs e)
        {
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                      delegate ()
                      {
                          if (e.PackageId == "Sample")
                          {
                              if (e.State == PackageState.Absent)
                              {
                                  Install_Button.Visibility = Visibility.Visible;
                                  Uninstall_Button.Visibility = Visibility.Collapsed;
                              }
                              else if (e.State == PackageState.Present)
                              {
                                  Uninstall_Button.Visibility = Visibility.Visible;
                                  Install_Button.Visibility = Visibility.Collapsed;
                              }
                          }
                      }));
        }

        private void OnPlanComplete(object sender, PlanCompleteEventArgs e)
        {
            if (e.Status >= 0)
                Bootstrapper.Engine.Apply(System.IntPtr.Zero);
        }

        private void OnExecuteProgress(object sender, ExecuteProgressEventArgs e)
        {
            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
                      delegate ()
                      {
                          progressBar.Value = e.ProgressPercentage;
                      }));
        }
    }
}
  • 创建WiX v4 Bundle项目BootstrapperDefaultUI,修改Bundle.wxs添加相关Payload:
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
  <Bundle Name="BootstrapperDefaultUI" Manufacturer="TODO Manufacturer" Version="1.0.0.0" UpgradeCode="7ee73ecd-5bb0-47e1-9e9b-25883e076b17">
    <BootstrapperApplication>
      <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\CustomBootstrapperApplication.dll" />
      <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\CustomBootstrapperApplication.dll.config" />
      <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\CustomBootstrapperApplication.pdb" />
      <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\WixToolset.Mba.Core.dll" />
      <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\WixToolset.Mba.Core.xml" />
      <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\WixToolset.Mba.Host.config" />

      <bal:WixManagedBootstrapperApplicationHost />
    </BootstrapperApplication>

    <Chain>
      <MsiPackage SourceFile="..\SampleWixApplication\bin\x86\Debug\en-US\SampleWixApplication.msi" bal:PrereqPackage="yes" />
    </Chain>
  </Bundle>
</Wix>

错误日志

[3264:2A08][2023-07-21T11:57:09]i000: Loading managed bootstrapper application.
[3264:2A08][2023-07-21T11:57:09]e000: Error 0x80131524: Failed to create the bootstrapper application.
[3264:2A08][2023-07-21T11:57:09]e000: Error 0x80131524: Failed to create the managed bootstrapper application.
[3264:2A08][2023-07-21T11:57:09]e000: Error 0x80131524: Failed to create BA.
[3264:2A08][2023-07-21T11:57:09]e000: Error 0x80131524: Failed to load BA.
[3264:2A08][2023-07-21T11:57:09]e000: Error 0x80131524: Failed while running
[3264:2A08][2023-07-21T11:57:09]i502: Cleanup begin.

解决方案

1. 修正CustomUI构造函数与工厂类实现

WiX v4中BootstrapperApplication要求构造函数同时接收IEngine和IBootstrapperCommand参数,修改代码:

// CustomUI.cs
public class CustomUI : BootstrapperApplication
{
    public CustomUI(IEngine engine, IBootstrapperCommand command) : base(engine, command)
    {
    }

    // 其他代码保持不变
}

// CustomUI.Factory.cs
protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand command)
{
    return new CustomUI(engine, command);
}

2. 完善Bundle中BootstrapperApplication配置

  • 添加WixToolset.Mba.Host.dll作为Payload(需替换为实际包路径)
  • 为bal:WixManagedBootstrapperApplicationHost指定必填属性
<BootstrapperApplication>
  <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\CustomBootstrapperApplication.dll" />
  <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\CustomBootstrapperApplication.dll.config" />
  <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\CustomBootstrapperApplication.pdb" />
  <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\WixToolset.Mba.Core.dll" />
  <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\WixToolset.Mba.Core.xml" />
  <Payload SourceFile="..\CustomBootstrapperApplication\bin\Debug\WixToolset.Mba.Host.config" />
  <!-- 添加Mba Host依赖 -->
  <Payload SourceFile="..\packages\WixToolset.Mba.Host.4.x.x\lib\net48\WixToolset.Mba.Host.dll" />
  
  <bal:WixManagedBootstrapperApplicationHost Id="CustomMBA" LicenseUrl="" ConfigFile="WixToolset.Mba.Host.config" />
</BootstrapperApplication>

3. 验证配置文件路径与内容

确保WixToolset.Mba.Host.config中的host节点正确指向自定义MBA程序集,同时确认.NET运行时配置与项目目标框架一致。

4. 清理重构项目

  • 删除所有项目的bin、obj目录
  • 先构建CustomBootstrapperApplication项目
  • 再构建Bundle项目,确保所有Payload文件正确复制到输出目录

内容的提问来源于stack exchange,提问作者Philipp Strobel

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 18:35:02