如何检测命令行或C#的MSBuild的状态 [英] How to detect the status of msbuild from command line or c#

查看:146
本文介绍了如何检测命令行或C#的MSBuild的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一结账,建立和C#应用程序的部署,并且需要知道检测到我的电话的MSBuild是否成功与否的最好方法。我试图从使用过程中的错误代码,但我不这样,这是总是准确的。



有没有经过下面的代码一种方法,我可以告诉有无的MSBuild .EXE程序成功完成?



由于
格兰特。

 
{
流程msbProcess =新工艺();
msbProcess.StartInfo.FileName = this.MSBuildPath;
msbProcess.StartInfo.Arguments = msbArguments;
msbProcess.Start();
msbProcess.WaitForExit();

如果(msbProcess.ExitCode!= 0)
{
//
}
,否则
{
$ // b $ b}

msbProcess.Close();
}
赶上(异常前)
{
//
}


解决方案

据我已经能够确定,当的MSBuild遇到错误返回退出代码> 0。如果没有遇到任何错误,它会返回退出代码0。我从来没有见过它代码<退出; 0



我用它在批处理文件:

 的MSBuild <&ARGS GT; 
如果ERRORLEVEL 1页转到errorDone

四年来使用它这样的,我已经从来没有理由质疑这种做法的正确性。



在MSDN论坛上的几个问题问同样的事情。例如: http://social.msdn.microsoft .COM /论坛/ EN-US /的MSBuild /线程/ a4ae6b2b-9b1f-4e59-86b4-370f44d73a85 。标准的反应是,实际上,如果错误级别为0,则没有错误。


i am writing up a checkout, build and deployment application in c# and need to know the best way to detect whether my call to msbuild has succeeded or not. i have tried to use the error code from the process but i dont this this is always accurate.

Is there a way through the code below that i can tell whether the msbuild.exe app completed successfully?

Thanks Grant.

try
{
    Process msbProcess = new Process();
    msbProcess.StartInfo.FileName = this.MSBuildPath;
    msbProcess.StartInfo.Arguments = msbArguments;
    msbProcess.Start();
    msbProcess.WaitForExit();

    if (msbProcess.ExitCode != 0)
    {
        //
    }
    else
    {
        //
    }

    msbProcess.Close();
}
catch (Exception ex)
{
    //
}

解决方案

As far as I've been able to determine, MSBuild returns an exit code > 0 when it encounters an error. If it doesn't encounter any errors, it returns an exit code of 0. I've never seen it exit with a code < 0.

I use it in a batch file:

msbuild <args>
if errorlevel 1 goto errorDone

In four years of using it this way, I've never had reason to question the correctness of this approach.

Several questions on the MSDN forums ask the same thing. For example: http://social.msdn.microsoft.com/forums/en-US/msbuild/thread/a4ae6b2b-9b1f-4e59-86b4-370f44d73a85. The standard response is, in effect, "if errorlevel is 0, then there was no error."

这篇关于如何检测命令行或C#的MSBuild的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆