Search code examples
visual-studiovsxvs-extensibility

How do I make Visual Studio automatically go to the first error in a build?


This is done manually by going to the "Error List" output window and double-clicking on the first error or pressing F8. Is there a way to automate this?

(I'm using C++ if that matters.)


Solution

  • vittore is on track...

    In VS press Alt+F11 to open the Macros IDE. Under 'MyMacros' open 'EnvironmentEvents' module and below these three lines

    'Event Sources End
    'End of automatically generated code
    #End Region
    

    paste this Sub:

    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")
            Beep()
            System.Windows.Forms.MessageBox.Show("Build failed!", "Build Events", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)
            DTE.ExecuteCommand("Edit.GoToNextLocation")
        End If
    End Sub
    

    Obviously, you can comment out or delete the Beep and the message box...