简体   繁体   中英

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM