简体   繁体   English

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

[英]Automatically stop Visual C++ 2008 build at first compile error?

I know I can compile individual source files, but sometimes -- say, when editing a header file used by many .cpp files -- multiple source files need to be recompiled. 我知道我可以编译单个源文件,但有时 - 比如说,当编辑许多.cpp文件使用的头文件时 - 需要重新编译多个源文件。 That's what Build is for. 这就是Build的用途。

Default behavior of the "Build" command in VC9 (Visual C++ 2008) is to attempt to compile all files that need it. VC9(Visual C ++ 2008)中“Build”命令的默认行为是尝试编译所有需要它的文件。 Sometimes this just results in many failed compiles. 有时这只会导致许多失败的编译。 I usually just watch for errors and hit ctrl-break to stop the build manually. 我通常只是观察错误并点击ctrl-break来手动停止构建。

Is there a way to configure it such the build stops at the very first compile error (not the first failed project build) automatically? 有没有办法配置它,以便构建在第一次编译错误 (不是第一次失败的项目构建)自动停止?

I came up with a better macro guys. 我想出了一个更好的宏观人物。 It stops immediately after the first error/s (soon as build window is updated). 它会在第一个错误/ s后立即停止(更新构建窗口时)。

Visual Studio -> Tools -> Macros -> Macro IDE... (or ALT+F11) 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 

Hope it works out for you guys. 希望它适合你们。

This can be done by adding a macro that is run in response to the event OnBuildProjConfigDone. 这可以通过添加为响应事件OnBuildProjConfigDone而运行的宏来完成。

The macro is as follows: 宏如下:

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

Yeah, this works fine on MSVC 2005-2010: 是的,这在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

I know the question was for VS 2008, but I stumbled across it when searching for the same answer for VS 2012. Since macros are no longer supported in 2012, macro solutions won't work anymore. 我知道这个问题是针对VS 2008的,但是当我为VS 2012搜索相同的答案时,我偶然发现了它。由于2012年不再支持宏,宏解决方案将不再适用。

You can download an extension that apparently works in VS 2010 and 2012 here . 您可以在此处下载显然适用于VS 2010和2012的扩展程序。 I can confirm that it works well in VS 2012. 我可以确认它在VS 2012中运行良好。

The original link to the extension was given in this response. 响应中给出了扩展的原始链接。

There is this post - not sure if it stops the build at the first error or the first failed project in a solution. 这篇文章 - 不确定它是否在第一个错误或解决方案中第一个失败的项目时停止构建。

Ctrl-break will also stop it manually. Ctrl-break也会手动停止。

Now if there was some way to stop it spending 10mins rebuilding intelisense after a build failed! 现在,如果有一些方法可以阻止它在构建失败后花费10分钟重建知识产权!

您也可以下载扩展,似乎适用于每个版本的Visual Studio

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM