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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/134796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 09:40:07  来源:igfitidea点击:

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

c++visual-studiovisual-studio-2008visual-c++visual-studio-2005

提问by jwfearn

I know I can compile individual source files, but sometimes -- say, when editing a header file used by many .cppfiles -- multiple source files need to be recompiled. That's what Build is for.

我知道我可以编译单个源文件,但有时——比如说,在编辑一个被许多文件使用的头.cpp文件时——需要重新编译多个源文件。这就是构建的目的。

Default behavior of the "Build" command in VC9 (Visual C++ 2008) is to attempt to compile all files that need it. Sometimes this just results in many failed compiles. I usually just watch for errors and hit ctrl-break to stop the build manually.

VC9 (Visual C++ 2008) 中“Build”命令的默认行为是尝试编译所有需要它的文件。有时这只会导致许多失败的编译。我通常只是注意错误并按 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?

有没有办法配置它,这样构建会在第一个编译错误(不是第一个失败的项目构建)时自动停止?

采纳答案by Eric Muyser

I came up with a better macro guys. It stops immediately after the first error/s (soon as build window is updated).

我想出了一个更好的宏家伙。它在第一个错误/秒后立即停止(更新构建窗口后)。

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.

希望对你们有用。

回答by jmatthias

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

回答by Anders Glent Buch

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

回答by RKG

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. I can confirm that it works well in VS 2012.

您可以在此处下载显然适用于 VS 2010 和 2012 的扩展。我可以确认它在 VS 2012 中运行良好。

The original link to the extension was given in thisresponse.

回复中给出了扩展的原始链接。

回答by Shocker

You can also download thisextension, seems to work for every version of Visual Studio

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

回答by Martin Beckett

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 分钟重建智能感知!