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();
}
问题是“如何知道编译是成功还是失败?”例如,我写了一些错误的字母,编译就会失败。但我怎么知道呢?
答案 0 :(得分:0)
DevEnv.exe在构建失败时设置exitcode
。只需读出这个exitcode并检查它是否为非零。关于该特定主题的StackOverflow有很多问题,但基本上你需要做的是
process.WaitForExit();
bool isCompilationSuccesful = (process.ExitCode == 0);