我有以下代码使用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);