Throwing Development Muses

Thursday, August 31, 2006

Cancel a failed build in VS.NET!

How annoying is it when a referenced project fails to build and VS.NET continues to try to compile everything underneath, ending up with screens of irrelevant errors?

Well, here is a very useful little nugget. This macro will stop the build if a project fails to compile, and it will work in vs2003, vs2005, vs2008 and vs2010.

In your macro explorer just add it to the module under MyMacros that contains the EnvironmentEvents module. On my machine this was in the default module named Module1.

'Cancels the build of a solution if a project build fails.
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
'The build failed...cancel any further builds.
DTE.ExecuteCommand("Build.cancel")
End If
End Sub