首次出现编译错误时自动停止 Visual C++ 2008 生成
Automatically stop Visual C++ 2008 build at first compile error?
我知道我可以编译单个源文件,但有时 - 例如,在编辑许多.cpp
文件使用的头文件时 - 需要重新编译多个源文件。 这就是构建的目的。
VC9 (Visual C++ 2008) 中"生成"命令的默认行为是尝试编译需要它的所有文件。 有时这只会导致许多编译失败。 我通常只观察错误并按 ctrl-break 手动停止构建。
有没有办法配置它,使构建在第一个编译错误(而不是第一个失败的项目构建)自动停止?
我想出了一个更好的宏家伙。它在第一个错误后立即停止(一旦生成窗口更新)。
Visual Studio -> Tools -> Macros -> Macro 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
我知道
这个问题是针对VS 2008的,但是在为VS 2012搜索相同的答案时,我偶然发现了它。由于 2012 年不再支持宏,宏解决方案将不再有效。
您可以在此处下载显然适用于VS 2010和2012的扩展。我可以确认它在VS 2012中运行良好。
此响应中提供了指向扩展的原始链接。
有这篇文章 - 不确定它是在解决方案中的第一个错误还是第一个失败的项目时停止构建。
按 Ctrl 中断也会手动停止它。
现在,如果有某种方法可以阻止它在构建失败后花费 10 分钟重建智能!
你也可以下载这个扩展,似乎适用于每个版本的Visual Studio
相关文章:
- Visual Studio 2015:Extern "C" 和 "export" 关键字
- 为cl.exe(Visual Studio代码)指定命令行C++版本
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在MS Visual Studio 2019中运行QT UI
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- Visual Studio Code - C++ Debugger 無法啟動
- Visual C++ constexpr Hints
- 为什么它不适用于Visual 2019的原因
- Visual Studio 2019:插入多个C++风格的单行注释
- Visual Studio Code "undefined reference to `WinMain@16'"
- visual在c++中将十进制数转换为二进制数
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- Visual Studio中的函数声明和函数定义问题
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual C++(VS2017)中用户定义的转换不明确
- Visual C++GC接口如何启用它以及要包含哪个库
- visual是否可以在c++中创建一个接收无限数量相同类型(或至少相当数量)参数的函数
- visual c++,如何获取解决方案目录中的代码
- Visual Studio mkl_link_tool.exe链接错误
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头