我知道我可以编译单个源文件,但有时候 - 比如说,编辑许多.cpp
文件使用的头文件时,需要重新编译多个源文件。这就是Build的用途。
VC9(Visual C ++ 2008)中“Build”命令的默认行为是尝试编译需要它的所有文件。有时这只会导致许多失败的编译。我通常只是注意错误并点击ctrl-break来手动停止构建。
有没有办法配置它,这样构建会自动停止在第一次编译错误(而不是第一次失败的项目构建)?
答案 0 :(得分:26)
我想出了一个更好的宏观人物。它会在第一个错误/ s后立即停止(更新构建窗口后)。
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 :(得分: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
答案 2 :(得分: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 :(得分:3)
我知道这个问题是针对VS 2008的,但是我在搜索VS 2012的相同答案时偶然发现了它。由于2012年不再支持宏,宏解决方案将不再适用。
您可以下载显然适用于VS 2010和2012 here的扩展程序。我可以确认它在VS 2012中运行良好。
扩展程序的原始链接在this响应中提供。
答案 4 :(得分:1)
答案 5 :(得分:1)
您还可以下载this扩展名,似乎适用于每个版本的Visual Studio