By default, Visual Studio will build all of the projects in your solution regardless of any errors.
The problem with this is that if the first project it builds contains an error, the resulting binary will not get generated. If any other projects depend on this (which is normally the case, as it was the first to be built) then they'll fail too, and so on to the end of the project heirarchy.
Pointless; you'll spend ages sitting around in a locked IDE unable to edit the error until the build finishes.
You might as well stop at the first error. You could of press Ctrl+Break (several times) and hope that VS will eventually stop. But, there's a better way: get Visual Studio to stop automatically after an error.
- Go to Tools/Macros/Macro Explorer
- Expand MyMacros
- Double click Module1
- This will bring up the macro in a new window. In that window, double click the EnvironmentEvents entry.
- From the drop-down (currently 'General', select 'Build Events')
- Select 'OnBuildProjConfigDone' and paste this in:
If Success = False Then 'The build failed...cancel any further builds. DTE.ExecuteCommand("Build.Cancel") End IfThe whole method should look like this:
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.OnBuildProjConfigDoneIf Success = False Then 'The build failed...cancel any further builds.DTE.ExecuteCommand("Build.Cancel")End IfEnd Sub
6 comments:
Could you give a little bit more information? How does one actually copy paste this macro? I go into the Macro menus in VS and can't find the one that is being referred to.
Sorry, not much of a VS macro guy.
Thanks,
John
a modified version from eric m
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
What is the benefit of this modified version?
you forgot a closing ' on your string.
oh, nevermind that is how you comment right?
The Visual Studio extension VS Commands has an option for this as well, and since VS 2012 no longer supports macros, using VS Commands is the easiest and most robust option at the moment. http://vscommands.squaredinfinity.com
Post a Comment