我想在我们的 WiX 自定义 BA 安装程序的第二版中启用升级。在我的Product.wxs中,产品ID设置为*,版本设置为2.0.0,升级代码与第一个版本相同。为了检测升级,我在 Boostrapper 中使用了 DetectRelatedBundle 事件处理程序。
MSI 中的 MajorUpgrade 标签如下所示:
<MajorUpgrade AllowDowngrades="no" DowngradeErrorMessage="A newer version of [ProductName] is already installed." AllowSameVersionUpgrades="no" Schedule="afterInstallInitialize" />
在我的安装程序用户界面中,我有一个“安装”按钮。在升级场景中单击此按钮时,我会调用 PlanAction 并传递 LaunchAction.Install。但是一旦安装开始,它会显示 BA 的另一个实例,我相信这是我当前的 BA 调用的旧包来卸载旧版本。为了隐藏新的 BA 实例并仅显示安装进度,我在 Bootstrapper 中进行了以下更改:
Bootstrapper.cs:
protected override void Run()
{
BootstrapperDispatcher = Dispatcher.CurrentDispatcher;
try
{
_model = new BootstrapperApplicationModel(this);
var uninstall = new UpgradeUninstall(_model);
if (uninstall.IsUpgradeUninstallation())
{
uninstall.PerformSequence();
}
else
{
//show install or uninstall main UI
this.WireUpEventHandlers();
_model.BootstrapperApplication.Engine.Detect();
Dispatcher.Run();
}
}
}
升级卸载.cs:
public class UpgradeUninstall
{
private BootstrapperApplicationModel _bootStrapperModel;
public UpgradeUninstall(BootstrapperApplicationModel model)
{
_bootStrapperModel = model;
}
public void Perform()
{
this.WireUpEventHandlers();
_bootStrapperModel.BootstrapperApplication.Engine.Detect();
}
public bool IsUpgradeUninstallation()
{
var action = _bootStrapperModel.BootstrapperApplication.Command.Action;
var display = _bootStrapperModel.BootstrapperApplication.Command.Display;
return action == LaunchAction.Uninstall && (display == Display.None || display == Display.Embedded);
}
private void WireUpEventHandlers()
{
_bootStrapperModel.BootstrapperApplication.DetectComplete += OnDetectComplete;
_bootStrapperModel.BootstrapperApplication.PlanComplete += OnPlanComplete;
_bootStrapperModel.BootstrapperApplication.ApplyComplete += OnApplyComplete;
}
private void OnDetectComplete(object sender, DetectCompleteEventArgs e)
{
this._bootStrapperModel.PlanAction(LaunchAction.Uninstall);
}
private void OnPlanComplete(object sender, PlanCompleteEventArgs e)
{
this._bootStrapperModel.ApplyAction();
}
private void OnApplyComplete(object sender, ApplyCompleteEventArgs e)
{
BootstrapperDispatcher.InvokeShutdown();
}
}
问题 1) 我如何让我的主 BA 实例(进行安装的实例)知道旧包的卸载已完成?现在发生的情况是,它能够成功卸载旧软件包,但没有执行新版本的安装。
问题2)我对WiX升级的理解是否正确? :)