使用子文件夹中的 C# 进程安装 setup.exe 包含多个 msi 文件的程序

Installing a program with setup.exe including multiple msi-files using C# process from a subfolder

在我的 C# WPF 应用程序中,我想安装另一个程序。另一个程序由一个 setup.exe、多个 msi 文件和一个 vcredist.exe 组成。我需要启动 setup.exe,因为它将一些参数和信息移交给 msi 文件,并使用程序现有版本的更新功能。所以我不能直接启动msi文件。

programPath = programPath + @"\setup.exe";
Process programsetup = Process.Start(programPath);
programsetup.WaitForExit();

文件存储在我的 C# 应用程序的根目录中。我的问题是我无法将文件移动到子文件夹,因为总是在根目录而不是子文件夹中搜索 msi 文件。

现在:

我的问题:如何移动子文件夹中的 setup.exe 和 msi 文件并从那里启动它?

我想要的:

当我这样做时,我在设置过程中遇到错误:..\myApp\client.msi not found.

此代码将直接启动 setup.exe。

属性 -> 右击打开 Resources.resx -> 左上添加现有文件 -> select 文件。

byte[] resourceFile = Properties.Resources.setup;
        string destination = Path.Combine(Path.GetTempPath(), "setup.exe");
        System.IO.File.WriteAllBytes(destination, resourceFile);
        Process.Start(destination);

我已经用 ProcessStartInfo.WorkingDirectory 解决了。

Problem/Solution:如果您使用 Process 启动安装文件,它会在安装过程中从同一目录加载一些 msi 文件,您需要设置 WorkingDirectory.

代码示例:

string ToolkitExe = myAppPath + @"\myApp\toolkit\setup.exe";
string ToolkitPath = myAppPath + @"\myApp\toolkit\";
ProcessStartInfo startInfo = new ProcessStartInfo(myAppPath + @"\myApp\toolkit\");
startInfo.WorkingDirectory = myAppPath;
Process p = Process.Start(startInfo);
p.WaitForExit();
RunAll();