我知道可以编译单个源文件,但有时候——比如当编辑一个被多个.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
希望这对你们有所帮助。
bool found = pPane.TextDocument.StartPoint.CreateEditPoint().FindPattern(": error")
的操作。这样做应该更快,因为它不依赖于在每个窗格更新时复制输出窗口的整个文本。 - Noah Richards可以通过添加一个宏来完成,该宏在响应事件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
DTE.Windows.Item(EnvDTE80.WindowKinds.vsWindowKindErrorList).Activate()
- Thomas