Visual Studio插件查找编译/生成错误

时间:2013-01-29 19:15:17

标签: c# visual-studio-2010 visual-studio visual-studio-addins

根据编译/构建的解决方案是否没有错误,我需要在构建完成时处理特定的逻辑。

如何检测上一次构建是否产生任何错误?

vsBuildState包含Done,InProgress和NotStarted的定义,我在哪里检查错误?

    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;
        _addInInstance = (AddIn)addInInst;
        _buildEvents = _applicationObject.Events.BuildEvents;            
        _buildEvents.OnBuildBegin += customBuildHandler;
        _buildEvents.OnBuildDone += customBuildEndHandler;
    }

    void customBuildEndHandler(vsBuildScope Scope, vsBuildAction Action)
    {
            if(IsLastBuildSuccessful) // How can I determine this?
            {
                    //Do Something
            }
    }

1 个答案:

答案 0 :(得分:1)

在事件处理程序中,您需要使用LastBuildInfo变量拦截上一次构建的状态。请参阅:http://msdn.microsoft.com/en-US/library/envdte.solutionbuild.lastbuildinfo(v=vs.100).aspx

var solution = _applicationObject.Solution;
var lastBuildState = solution.SolutionBuild.LastBuildInfo; 
if(lastBuildState == 0)
    //Build succeeded