自动停止Visual C ++ 2008年生成第一次编译错误?

时间:2020-03-06 14:44:12  来源:igfitidea点击:

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

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

有没有一种方法可以配置它,以使构建在第一个编译错误(不是第一个失败的项目构建)处自动停止?

解决方案

这篇文章不确定是否在解决方案中的第一个错误或者第一个失败的项目时停止构建。

Ctrl-break也可以手动将其停止。

现在,如果有某种方法可以阻止它在构建失败后花费10分钟来重建智能感知!

这可以通过添加响应事件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

我想出了一个更好的宏人。它在第一个错误后立即停止(很快将更新构建窗口)。

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

希望它对你们有用。