首先自动停止Visual C++ 2008编译编译错误?
问题描述:
我知道我可以编译单个源文件,但有时候 - 比如编辑许多.cpp
文件使用的头文件 - 需要重新编译多个源文件。这就是Build的用途。首先自动停止Visual C++ 2008编译编译错误?
VC9(Visual C++ 2008)中“Build”命令的默认行为是尝试编译所有需要它的文件。有时这只会导致许多失败的编译。我通常只是注意错误并按ctrl-break手动停止构建。
有没有一种方法来配置它,以便自动停止在第一编译错误(而不是第一个失败的项目构建)?
答
我想出了一个更好的宏观家伙。它在第一个错误/秒之后立即停止(即将更新构建窗口)。
的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
希望工程出了你们。
答
这可以通过添加一个响应事件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
答
呀,这正常工作的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
尊敬的人[未来](http://xkcd.com/979) - 在VS 2010+,试试[ StopOnFirstBuildError](http://visualstudiogallery.msdn.microsoft.com/91aaa139-5d3c-43a7-b39f-369196a84fa5)扩展 – brichins 2013-02-07 16:20:33