Things You'll Need:
- Visual Studio 2005 or 2008
-
Step 1
Visual Studio menu for Macros IDERun 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.
-
Step 2
Macros editorDouble click on "MyMacros" and then double click on "EnvironmentEvents". This should bring up some VB script code in the main editor window.
-
Step 3
Macros editor with OnBuildProjConfigDonePaste 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
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
on 7/9/2009 This will be helpful to know for if I get it.
ericmuyser said
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.