0

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.)

BIBD
  • 15,107
  • 25
  • 85
  • 137
Jon
  • 5,275
  • 5
  • 39
  • 51

2 Answers2

1

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...

Dean Kuga
  • 11,878
  • 8
  • 54
  • 108
  • Thanks, the "DTE.ExecuteCommand("Edit.GoToNextLocation")" line was what I was looking for. However this doesn't necessarily go to the first error - any idea how to prevent this event from being called more than once per build? – Jon Mar 30 '10 at 05:06
  • Found another post here at SO (http://stackoverflow.com/questions/134796/how-to-automatically-stop-visual-c-build-at-first-compile-error) where they used OutputWindowEvents_OnPaneUpdated event instead... – Dean Kuga Mar 30 '10 at 06:23
  • Yes I'm using that technique (by Eric Muyser) to cancel the build. But it still has the same issue of being called more than once. – Jon Mar 30 '10 at 06:52
0

Adding to the previous answer:

I suggest View.NextError command instead of Edit.GoToNextLocation. Do not get confused by its group (View), it actually GOes TO error location in the editor, like if you double-click error item in the error list.

You can also map it to the keyboard this way:

  • Ctrl+Shift+PgUp = View.GoToPreviousError
  • Ctrl+Shift+PgDn = View.GoToNextError

This will allow you to check for errors (and move between them in editor) even without need of displaying the error window and even without running the build.

miroxlav
  • 11,796
  • 5
  • 58
  • 99