开发者

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

开发者 https://www.devze.com 2022-12-25 15:15 出处:网络
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?

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+开发者_如何学Go+ if that matters.)


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消