Skip to content
 

Automatically Cancelling a Failed Build in Visual Studio

Stumbled across this little tip on how to automatically cancel a build in progress after getting an error. You normally have to wait for visual studio to try to finish building all of the remaining projects before getting a chance to fix an the issue and this can take a few minutes if you have a lot of projects in your solution.

Step 1: Open the Visual Studio macros IDE by navigating to Tools –> Macros –> Macros IDE.

Step 2: Double click on “MyMacros” and then on “EnvironmentEvents”. You should now be looking at a VB code editor window.

Step 3: Paste the following code directly before the “End Module” line:

Private Sub BuildEvents_OnBuildProjConfigDone(ByVal Project As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String, ByVal Success As Boolean) Handles BuildEvents.OnBuildProjConfigDone
 
    If Success = False Then
        DTE.ExecuteCommand("Build.Cancel")
    End If
 
End Sub

Step 4: Save and close the Macro Editor window and IDE.

All done!

2 Comments

  1. Surge says:

    This is a great trick, thanks for posting it. I have had this problem and waiting is not the most productive use of my time.

  2. Bryan says:

    Nice tip, Dan.

    Hard to believe that Visual Studio doesn’t have this feature on its own. Aside from the time-savings in the build this prevents an additional 20-30 errors you might get because dependent projects didn’t get the correct assembly. It fails instantly and you get only meaningful errors.

Leave a Reply

(required)


8 + three =