首页 文章

回滚到以前版本的WiX捆绑软件安装程序

提问于
浏览
0

我有两个msi软件包的WiX软件包:A和B.首先,我成功安装了软件包版本1.0.0.0 . 然后我安装MajorUpgrade版本2.0.0.0 . 包A成功升级 . 程序包B升级失败并开始回滚 .

我将msi包升级定义为: <MajorUpgrade AllowSameVersionUpgrades="yes" Schedule="afterInstallInitialize" DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

程序包B还原为1.0.0.0版 . 包装通过删除支持的卷筒 . 因此,捆绑包保持不一致状态 .

如果更新失败,我需要将整个捆绑包恢复到版本1.0.0.0 . 可能吗?

1 回答

  • 2

    没有标准的方法来实现它,因为WiX不支持多MSI事务 .

    我找到了适用于我的解决方法 . 我使用 Custom Bootstrapper Application ,所以我可以在C#代码中处理失败事件 . 如果您使用WiX标准引导程序应用程序(WiXStdBA),它将无法帮助您 .

    如果更新失败,我将以静默修复模式从Windows软件包缓存调用以前的软件包安装程序 . 它恢复了以前的状态 .

    下一个代码表达了这个想法:

    Bootstrapper.PlanRelatedBundle += (o, e) => { PreviousBundleId = e.BundleId; };
    
    Bootstrapper.ApplyComplete += OnApplyComplete;
    
    private void OnApplyComplete(object sender, ApplyCompleteEventArgs e)
    {
        bool updateFailed = e.Status != 0 && _model.InstallationMode == InstallationMode.Update;
        if (updateFailed)
        {
            var registryKey = string.Format("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\{0}", VersionManager.PreviousBundleId);
            RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(registryKey)
                ?? RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).OpenSubKey(registryKey);
    
            if (key != null)
            {
                string path = key.GetValue("BundleCachePath").ToString();
                var proc = new Process();
                proc.StartInfo.FileName = path;
                proc.StartInfo.Arguments = "-silent -repair";
                proc.Start();
                proc.WaitForExit();
            }
        }
    }
    

相关问题