I have the following code which builds a project using Process.Start() and 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();
}
How can I detect whether the compilation was successful or not?
DevEnv.exe sets an exitcode
when the build fails. Simply read out this exitcode and check if it is non-zero. There are a lot of questions on StackOverflow on that particular topic, but essentially what you need to do is
process.WaitForExit();
bool isCompilationSuccesful = (process.ExitCode == 0);