我有以下代码,它使用 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
。只需读出此退出代码并检查它是否为非零。关于该特定主题的StackOverflow上有很多问题,但基本上您需要做的是
process.WaitForExit();
bool isCompilationSuccesful = (process.ExitCode == 0);