wix - 如何在 WiX 中读取自定义操作的可执行输出?

标签 wix windows-installer wix3.5 custom-action

我正在 WiX 中制作 MSI 安装程序。在安装期间,我想从 custom action 运行可执行文件并获取其标准输出(不是返回码)以供以后在安装过程中使用(据说带有 Property 元素)。

如何在 WiX (3.5) 中实现它?

最佳答案

我将此代码用于类似的任务(它是一个 C# DTF 自定义操作):

// your process data
ProcessStartInfo processInfo = new ProcessStartInfo() {
   CreateNoWindow = true,
   LoadUserProfile = true,
   UseShellExecute = false,
   RedirectStandardOutput = true,
   StandardOutputEncoding = Encoding.UTF8,
   ...
};

Process process = new Process();
process.StartInfo = processInfo;
process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
  {
     if (!string.IsNullOrEmpty(e.Data) && session != null)
     {
         // HERE GOES THE TRICK!
         Record record = new Record(1);
         record.SetString(1, e.Data);
         session.Message(InstallMessage.ActionData, record);
      }
  };

process.Start();
process.BeginOutputReadLine();
process.WaitForExit();

if (process.ExitCode != 0) {
   throw new Exception("Execution failed (" + processInfo.FileName + " " + processInfo.Arguments + "). Code: " + process.ExitCode);
}

process.Close();

关于wix - 如何在 WiX 中读取自定义操作的可执行输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12092447/

相关文章:

visual-studio - WIX 3.5 Visual Studio 项目为已安装文件的 .NET 版本创建多个 MSI

vbscript - 当没有文件时,InstallShield 使用 VBScript 和 CustomAction 删除文件失败

WiX安装程序未在卸载时删除文件

wix - 如何使用 wix 将多个元素添加到 XML 配置文件中?

wix - 在 WIX 中运行时为快捷方式动态分配名称

c# - 使用 WiX C#/.NET 4 自定义操作时出现错误 2896

iis-7 - Wix 3.5 和 IIS7 - WriteIIS7ConfigChanges 失败 - 虽然尝试将三个 Web 应用程序作为虚拟目录安装到默认网站

wix - 自定义操作中的条件

c# - 在WiX安装中从C#自定义操作调用PowerShell命令

wix - 包括所有依赖项