1

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

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

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
            }
    }
4

1 回答 1

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
于 2013-01-30T19:19:09.200 回答