无法用C#中的空格启动命令行



我需要执行的命令行是"C:Program Files (x86)Microsoft Visual Studio2019EnterpriseCommon7IDEdevenv.exe" /Run "C:unityunityMRTK TutorialBuildsMRTK Tutorial.sln"

这在windows命令行中工作时没有问题,我将其格式化为visual studio 的字符串

当从C#运行时,该命令从不执行,并且result的内容是""

System.Diagnostics.ProcessStartInfo procStartInfo =  new System.Diagnostics.ProcessStartInfo("C:\Program Files(x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe", " /Run "C:\unity\unity\MRTK Tutorial\Builds\MRTK Tutorial.sln"");
// The following commands are needed to redirect the standard output.
// This means that it will be redirected to the Process.StandardOutput StreamReader.
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
// Do not create the black window.
procStartInfo.CreateNoWindow = true;
// Now we create a process, assign its ProcessStartInfo and start it
System.Diagnostics.Process proc = new System.Diagnostics.Process();

您可以尝试使用以下代码来执行devenv.exe。

var devEnvPath = @"C:Program Files (x86)Microsoft Visual Studio2019EnterpriseCommon7IDEdevenv.exe";
string SolutionFile = @"D:Testtestconsoletestconsole.sln";
ProcessStartInfo startInfo = new ProcessStartInfo(devEnvPath);
startInfo.Arguments = "/Run " + SolutionFile;
Process process = new Process();
process.StartInfo = startInfo;
process.Start();
process.WaitForExit();
Console.ReadKey();

根据我的测试,上面的代码将打开vs2019并打开启动项目。