首次编译错误时自动停止Visual C++ 2008构建?

jwf*_*arn 47 c++ visual-studio-2005 visual-studio-2008 visual-studio visual-c++

我知道我可以编译单个源文件,但有时 - 比如说,在编辑许多文件使用的头.cpp文件时 - 需要重新编译多个源文件.这就是Build的用途.

VC9(Visual C++ 2008)中"Build"命令的默认行为是尝试编译需要它的所有文件.有时这只会导致许多失败的编译.我通常只是观察错误并点击ctrl-break来手动停止构建.

有没有办法配置它,以便构建在第一次编译错误(不是第一次失败的项目构建)自动停止?

Eri*_*ser 27

我想出了一个更好的宏观人物.它会在第一个错误/ s后立即停止(更新构建窗口时).

Visual Studio - >工具 - >宏 - >宏IDE ...(或ALT + F11)

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

    If found > 0 Then
        DTE.ExecuteCommand("Build.Cancel")
    End If

End Sub 
Run Code Online (Sandbox Code Playgroud)

希望它适合你们.

  • 您不需要使用全选;您应该能够执行类似“boolfound = pPane.TextDocument.StartPoint.CreateEditPoint().FindPattern(": error")”之类的操作。它也应该更快,因为它不依赖于在每次窗格更新时复制输出窗口的整个文本。 (2认同)

jma*_*ias 17

这可以通过添加为响应事件OnBuildProjConfigDone而运行的宏来完成.

宏如下:

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")
  End If

End Sub
Run Code Online (Sandbox Code Playgroud)

  • 这不是原始海报所寻求的,但它正是我所寻找的.如果不是很明显,可以通过转到Tools-> Macros-> Macros IDE来添加它,打开EnvironmentEvents并将其粘贴到那里. (7认同)
  • 是的,但对我而言足够接近(而不是在停止之前建造接下来的20个左右的项目). (4认同)

小智 8

是的,这在MSVC 2005-2010上运行良好:

Public Module EnvironmentEvents
  Private Sub OutputWindowEvents_OnPaneUpdated(ByVal pPane As OutputWindowPane) Handles OutputWindowEvents.PaneUpdated
    If Not (pPane.Name = "Build") Then Exit Sub

    Dim foundError As Boolean = pPane.TextDocument.StartPoint.CreateEditPoint().FindPattern(": error")
    Dim foundFatal As Boolean = pPane.TextDocument.StartPoint.CreateEditPoint().FindPattern(": fatal error")

    If foundError Or foundFatal Then
      DTE.ExecuteCommand("Build.Cancel")
    End If
  End Sub
End Module
Run Code Online (Sandbox Code Playgroud)