我怎么知道编译是否成功或是否由于process.start()和devenv.exe而失败?

问题描述 投票:1回答:1

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

如何检测编译是否成功?

c# compilation process.start devenv
1个回答
0
投票

DevEnv.exe在构建失败时设置exitcode。只需读出此退出代码并检查它是否为非零即可。关于该特定主题,在StackOverflow上有很多问题,但是本质上您需要做的是

process.WaitForExit();
bool isCompilationSuccesful = (process.ExitCode == 0);
© www.soinside.com 2019 - 2024. All rights reserved.