【问题标题】:How to install / uninstall single msi from wix custom bootstrapper bundle containing multiple MSIs like add/remove feature of Setup project?如何从包含多个 MSI 的 wix 自定义引导程序包中安装/卸载单个 msi,例如安装项目的添加/删除功能?
【发布时间】:2013-05-16 14:23:11
【问题描述】:

我在 wix 包中有 2 个 msi 我正在使用 wix 3.7 的自定义引导程序。我的安装、卸载和取消命令完美运行。当我尝试使用以下方式提供从捆绑包中添加/删除 msi 的功能时:

 this.ModifyCommand = new DelegateCommand(() => this.model.PlanAction(LaunchAction.Modify), () => this.state == InstallState.Present);    

它没有按预期工作。我正在使用下面的代码来检测包

    protected void DetectPackageComplete(object sender,DetectPackageCompleteEventArgs e)
    {
        //System.Diagnostics.Debugger.Launch();

        if (e.PackageId.Equals("Setup1.msi", StringComparison.Ordinal))
        {
            this.State = e.State == PackageState.Present ? InstallState.Present : InstallState.NotPresent;
            this.model.LogMessage("Setup1.msi"+this.State.ToString());
        }

        if (e.PackageId.Equals("Setup2.msi", StringComparison.Ordinal))
        {
            this.State = e.State == PackageState.Present ? InstallState.Present : InstallState.NotPresent;
            this.model.LogMessage("Setup2.msi" + this.State.ToString());
        }
    }

全新安装后,我的 UI 显示添加/删除、删除、修复、重新安装选项以供下次安装使用,我可以从捆绑包中卸载单个 msi,但下次它不会检测到剩余的包。

如果我卸载 setup2.msi,它会显示添加/删除屏幕,但修改按钮被禁用,如果我卸载 setup1.msi,它会要求重新安装。

【问题讨论】:

    标签: c# visual-studio-2010 wix wix3.7


    【解决方案1】:

    最后我解决了这个问题,我不知道它是对还是错,但在我实施它的时候,它对我来说很好。

    这里是代码

    在管理的 BA 中添加以下事件

        private void PlanPackageBegin(object sender, PlanPackageBeginEventArgs e)
        {         
    
            if (e.PackageId.Equals("Setup1.msi", StringComparison.Ordinal))
            {
                this.model.LogMessage("PlanPackageBegin Setup1 : " + e.State);
    
                string IsSetup1= this.model.BootstrapperApplication.Engine.StringVariables["chkSetup1"];
    
                if (IsSetup1== "True")
                {
                    e.State = RequestState.Present;
                }
                else
                {
                    e.State = RequestState.Absent;
                }
    
                this.model.LogMessage("PlanPackageBegin Setup1 : " + e.State);
    
            }
    
            if (e.PackageId.Equals("Setup2.msi", StringComparison.Ordinal))
            {
                this.model.LogMessage("PlanPackageBegin Setup2 : " + e.State);
    
                string IsSetup2= this.model.BootstrapperApplication.Engine.StringVariables["chkSetup2"];
    
                if (IsSetup2== "True")
                {
                    e.State = RequestState.Present;
                }
                else
                {
                    e.State = RequestState.Absent;
                }
    
                this.model.LogMessage("PlanPackageBegin Setup2 : " + e.State);
            }
          }
    

    将下面一行添加到 WireUpEventHandlers() 函数

       this.model.BootstrapperApplication.PlanPackageBegin +=this.PlanPackageBegin;  
    

    这里 chkSetup1 和 chkSetup2 值从为特征树和 SetBurnVariable 函数制作的自定义 UI 设置为 True 或 False。

    希望对大家有所帮助。

    【讨论】:

      【解决方案2】:

      最后我解决了这个问题,我不知道它是对还是错,但在我实施它的时候,它对我来说很好。

      这是manged BA中事件的代码

          private void PlanPackageBegin(object sender, PlanPackageBeginEventArgs e)
          {         
      
              if (e.PackageId.Equals("Setup1.msi", StringComparison.Ordinal))
              {
                  this.model.LogMessage("PlanPackageBegin Setup1 : " + e.State);
      
                  string IsSetup1= this.model.BootstrapperApplication.Engine.StringVariables["chkSetup1"];
      
                  if (IsSetup1== "True")
                  {
                      e.State = RequestState.Present;
                  }
                  else
                  {
                      e.State = RequestState.Absent;
                  }
      
                  this.model.LogMessage("PlanPackageBegin Setup1 : " + e.State);
      
              }
      
              if (e.PackageId.Equals("Setup2.msi", StringComparison.Ordinal))
              {
                  this.model.LogMessage("PlanPackageBegin Setup2 : " + e.State);
      
                  string IsSetup2= this.model.BootstrapperApplication.Engine.StringVariables["chkSetup2"];
      
                  if (IsSetup2== "True")
                  {
                      e.State = RequestState.Present;
                  }
                  else
                  {
                      e.State = RequestState.Absent;
                  }
      
                  this.model.LogMessage("PlanPackageBegin Setup2 : " + e.State);
              }
            }
      

      将下面一行添加到 WireUpEventHandlers() 函数

         this.model.BootstrapperApplication.PlanPackageBegin +=this.PlanPackageBegin;  
      

      这里 chkSetup1 和 chkSetup2 值从为特征树和 SetBurnVariable 函数制作的自定义 UI 设置为 True 或 False。 希望对大家有所帮助。

      【讨论】:

        猜你喜欢
        • 2013-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-23
        • 1970-01-01
        • 1970-01-01
        • 2015-03-25
        相关资源
        最近更新 更多