我如何知道编译是成功还是失败 process.start() 和 devenv.exe?

How do I know if compilation was sucessful or it failed with process.start() and devenv.exe?

我有以下使用 Process.Start() 和 devenv.exe 构建项目的代码:

RegistryKey rkey = Registry.LocalMachine;

//找到devenv.exe路径
RegistryKey rkey1 = rkey.OpenSubKey(REGISTKEY, false);
string devenvPath = rkey1.GetValue("").ToString();

ProcessStartInfo startInfo = new ProcessStartInfo(devenvPath);
startInfo.Arguments = "/rebuild \"debug|x86\" " + solutionPath;

//执行编译过程
Process process = new Process();
process.StartInfo = startInfo;

try
{
    process.Start();
    process.WaitForExit();
}

如何检测编译是否成功?

DevEnv.exe 在构建失败时设置 exitcode。只需读出此退出代码并检查它是否非零。 Whosebug 上有很多关于该特定主题的问题,但基本上您需要做的是

process.WaitForExit();
bool isCompilationSuccesful = (process.ExitCode == 0);