首页 > 解决方案 > Wix 引导程序有条件安装

问题描述

我创建了一个带有 2 个复选框的用户界面的 wix 引导程序应用程序。用户可以选择安装什么。这是我的引导程序应用程序的一部分:

 <MsiPackage 
        InstallCondition="ClientCondition"
        DisplayInternalUI='yes'
        Visible="yes"
        SourceFile="D:\Project\FirstInstaller.msi"
      />
      <MsiPackage
        InstallCondition="ServerCondition"
        DisplayInternalUI='yes'
        Visible="yes"
        SourceFile="D:\Project\SecondInstaller.msi"
      />

问题:例如,我已经安装了 FirstInstaller,我正在尝试安装第二个。由于错误情况,我的 FirstInstaller 将被卸载。但这不是我所期望的。我该如何解决这个问题并为链中的 Msi 包提供一些“忽略”价值?

标签: wixbootstrapper

解决方案


我不知道您的引导程序是用哪种语言编写的,但是,作为选项,您可以通过 cmd 和 msiexec 命令直接从您的代码中控制您的 msi 安装。

C# 的代码示例:

        var command = @"/c msiexec /i c:\path\to\package.msi";
        //for silent: /quiet /qn /norestart 
        //for log: /log c:\path\to\install.log 
        //with properties: PROPERTY1=value1 PROPERTY2=value2";
        var output = string.Empty;
        using (var p = new Process())
        {
            p.StartInfo = new ProcessStartInfo()
            {
                FileName = "cmd.exe",
                Arguments = command,
                UseShellExecute = false,
                RedirectStandardError = true,
                RedirectStandardOutput = true,
                CreateNoWindow = true,
            };
            p.Start();
            while (!p.StandardOutput.EndOfStream)
            {
                output += $"{p.StandardOutput.ReadLine()}{Environment.NewLine}";
            }
            p.WaitForExit();
            if (p.ExitCode != 0)
            {
                throw new Exception($"{p.ExitCode}:{ p.StandardError.ReadToEnd()}");
            }
            Console.WriteLine(output);
            Console.ReadKey();
        }

推荐阅读