46

我知道我可以编译单个源文件,但有时候 - 比如编辑许多.cpp文件使用的头文件 - 需要重新编译多个源文件。这就是Build的用途。首先自动停止Visual C++ 2008编译编译错误?

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

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

+2

尊敬的人[未来](http://xkcd.com/979) - 在VS 2010+,试试[ StopOnFirstBuildError](http://visualstudiogallery.msdn.microsoft.com/91aaa139-5d3c-43a7-b39f-369196a84fa5)扩展 – brichins 2013-02-07 16:20:33

回答

25

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

的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 

希望工程出了你们。

1

this post - 如果它停靠在第一个错误的生成或在溶液中第一个失败的项目不能确定。

Ctrl-break还会手动停止它。

现在,如果有某种方式可以阻止它在构建失败后花10分钟重建intelisense!

+0

但ctrl-break破坏当时正在创建的文件,因此您必须显式重新编译它们。 – Lev 2008-09-26 12:02:17

+2

链接中描述的方法在第一个PROJECT失败时停止构建,而不是第一个编译错误。 – jwfearn 2008-10-13 16:41:54

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 
+0

此方法在第一个PROJECT失败时停止构建,而不是第一个编译错误。 – jwfearn 2008-10-13 16:47:37

+4

是的,但对我来说已经足够接近了(而不是在停下来之前建设接下来的20个左右的项目)。 – jmatthias 2008-12-07 06:37:01

9

呀,这正常工作的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 
3

我知道这个问题是2008年的VS,但我碰到它跌跌撞撞寻找相同的答案VS 2012年时,由于宏是没有在2012年得到更长时间的支持后,宏观解决方案将不再适用。

您可以下载,显然工作在VS 2010和2012年here的延伸。我可以肯定,它运作良好,在2012年VS

原路段的延伸在this响应给出。

1

您也可以下载this扩展,似乎为Visual Studio的每个版本的工作