eHow launches Android app: Get the best of eHow on the go.

How To

How to Automatically Stop a Visual Studio Build on an Error

Member
By 17of26
User-Submitted Article
(2 Ratings)
Automatically Stop a Visual Studio Build on an Error
Automatically Stop a Visual Studio Build on an Error

When you do a build in Visual Studio 2005 or 2008, the compiler will attempt to build the entire solution even if one of the projects in the solution fails to build. This can be annoying if your solution has a lot of projects in it and one of the first ones fails to build. This article shows you how to automatically stop a Visual Studio build on an error.

Difficulty: Easy
Instructions

Things You'll Need:

  • Visual Studio 2005 or 2008
  1. Step 1
    Visual Studio menu for Macros IDE
    Visual Studio menu for Macros IDE

    Run Visual Studio and go to Tools->Macros->Macros IDE. Alternatively, you can use the shortcut key which is Alt+F11. This will bring up the interface for defining macros that respond to various environment events in Visual Studio.

  2. Step 2
    Macros editor
    Macros editor

    Double click on "MyMacros" and then double click on "EnvironmentEvents". This should bring up some VB script code in the main editor window.

  3. Step 3
    Macros editor with OnBuildProjConfigDone
    Macros editor with OnBuildProjConfigDone

    Paste the following code in right before the "End Module" line of code:
    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

    This macro will get run for the "OnBuildProjConfigDone" build event which gets fired each time a project finishes building. The macro checks to see whether or not the build was successful. If the build failed then the macro will execute the "Build.Cancel" command which instructs Visual Studio to stop the build. It's worth noting that if there are multiple errors in a single project the build will not stop on the first error in the project but it will stop after a project completes its attempt to build.

Comments  

sonicth said

Flag This Comment

on 7/12/2009 i've modified it to handle fatal errors :p
thats somewhat of a hack, but interesting indeed, thanks for posting!

Private Sub OutputWindowEvents_OnPaneUpdated(ByVal pPane As OutputWindowPane) Handles OutputWindowEvents.PaneUpdated
If Not (pPane.Name = "Build") Then Exit Sub

pPane.TextDocument.Selection.SelectAll()
Dim Context As String = pPane.TextDocument.Selection.Text
pPane.TextDocument.Selection.EndOfDocument()

Dim found As Integer = Context.IndexOf(": error ")
Dim foundFatal As Integer = Context.IndexOf(": fatal error")

If found > 0 Or foundFatal > 0 Then
DTE.ExecuteCommand("Build.Cancel")
End If

End Sub

karileighk said

Flag This Comment

on 7/9/2009 This will be helpful to know for if I get it.

ericmuyser said

Flag This Comment

on 7/5/2009 I came up with a better macro guys. It stops immediately after the first error/s (soon as build window is updated).

Visual Studio -> Tools -> Macros -> Macro IDE... (or ALT+F11)

Private Sub OutputWindowEvents_OnPaneUpdated(ByVal pPane As OutputWindowPane) Handles OutputWindowEvents.PaneUpdated
If Not (pPane.Name = "Build") Then Exit Sub

pPane.TextDocument.Selection.SelectAll()
Dim Context As String = pPane.TextDocument.Selection.Text
pPane.TextDocument.Selection.EndOfDocument()

Dim found As Integer = Context.IndexOf(": error ")

If found > 0 Then
DTE.ExecuteCommand("Build.Cancel")
End If

End Sub

Hope it works out for you guys.

Post a Comment

Post a Comment
  • Have you done this? Click here to let us know.
I Did This

Related Ads

Internet
Virginia DeBolt,

Meet Virginia DeBolt eHow's Internet Expert.

Get Free Internet Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

Demand Media
eHow_eHow Technology and Electronics