几天来一直在努力寻找 Wix Toolset v4 的托管 BA 的工作示例。其中大部分都在 v3 中。我与这里的现有问题有完全相同的问题,还有一些类似的问题但没有答案:
Wix Bundle 托管引导程序应用程序 - 错误 0x80131524:无法创建引导程序应用程序
基本上,我的安装程序有一个使用 WPF(.Net Framework)构建的自定义 UI、一个使用 Wix Toolset v4 构建的 msi 并使用 Bundle 创建 exe。
日志说:
错误0x80131508:无法创建引导程序应用程序。 错误 0x80131508:无法创建托管引导程序应用程序。 错误0x80131508:无法创建BA。 错误0x80131508:无法加载BA。 错误 0x80131508:运行时失败
这是UI的项目文件:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\x86\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.DirectoryServices.AccountManagement" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="WixToolset.Mba.Core" Version="4.0.*" PrivateAssets="All" GeneratePathProperty="true" />
</ItemGroup>
<ItemGroup>
<Content Include="WixToolset.Mba.Host.config" CopyToOutputDirectory="PreserveNewest" />
<Content Include="$(PkgWixToolset_Mba_Core)\runtimes\win-x86\native\mbanative.dll">
<Visible>false</Visible>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<IsAssembly>false</IsAssembly>
</Content>
</ItemGroup>
<ItemGroup>
<Page Include="AdditionalStyles.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
</Project>
自定义UI.cs
using System.Windows.Threading;
using WixToolset.Mba.Core;
namespace MyOwnApp
{
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);
}
protected override void OnStartup(StartupEventArgs args)
{
base.OnStartup(args);
this.engine.Log(LogLevel.Standard, nameof(CustomUI));
}
protected override void OnShutdown(ShutdownEventArgs args)
{
base.OnShutdown(args);
var message = "Shutdown," + args.Action.ToString() + "," + args.HResult.ToString();
this.engine.Log(LogLevel.Standard, message);
}
}
}
自定义UIFactory:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyOwnApp
{
using WixToolset.Mba.Core;
public class CustomUIFactory : BaseBootstrapperApplicationFactory
{
private static int loadCount = 0;
protected override IBootstrapperApplication Create(IEngine engine, IBootstrapperCommand bootstrapperCommand)
{
if (loadCount > 0)
{
engine.Log(LogLevel.Standard, $"Reloaded {loadCount} time(s)");
}
++loadCount;
return new CustomUI(engine);
}
}
}
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="MyOwnApp" />
</wix.bootstrapper>
</configuration>
尝试了几乎所有在互联网上找到的例子都无济于事。 :(
原始 WiX v3 WPF WixBA 示例已更新为 WiX v4:https://github.com/wixtoolset/wix/tree/develop/src/test/burn/WixToolset.WixBA