Question

There are specific logic that I need to handle on build completed depending on whether or not the solution compiled/built with no error.

How can I detect if the last build generated any error?

vsBuildState contains definition for Done, InProgress, and NotStarted, where do I check for errors?

    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
            }
    }
Was it helpful?

Solution

Inside the event handler you need to intercept the state of last build using the LastBuildInfo variable. Refer : 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top