我知道我可以编译单个源文件,但有时——比如说,在编辑许多.cpp
文件使用的头文件时——需要重新编译多个源文件。这就是 Build 的用途。
VC9 (Visual C++ 2008) 中“Build”命令的默认行为是尝试编译所有需要它的文件。有时这只会导致许多失败的编译。我通常只是注意错误并按 ctrl-break 手动停止构建。
有没有办法配置它,使构建在第一个编译错误(不是第一个失败的项目构建)时自动停止?
我知道我可以编译单个源文件,但有时——比如说,在编辑许多.cpp
文件使用的头文件时——需要重新编译多个源文件。这就是 Build 的用途。
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
你也可以下载这个扩展,似乎适用于每个版本的 Visual Studio