如何在 Visual Studio 中与任务列表标记匹配的行上设置断点?

发布于 2024-08-18 23:56:16 字数 1281 浏览 1 评论 0原文

这很整洁: 如何在每个位置放置一个断点我的应用程序中的 MessageBox?

但是有没有办法对任务列表中的令牌(“查看”菜单 ->“任务列表”)执行此类操作? 例如,我有这样的代码:

int a=0; //RETEST this code
int b=0; //RETEST this code

在上面,RETEST 是一个任务列表标记;有没有一种方法可以快速在与某个任务列表标记匹配的所有行上设置断点,而不必转到找到该标记的每一行?

更新

这是宏(灵感来自如何将调试断点添加到 Visual Studio 中“查找结果”窗口中显示的行):

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.IO
Imports System.Text.RegularExpressions

Public Module CustomMacros
    Sub SetBreakpointsUsingTaskList()

        Dim TL As TaskList = DTE.ToolWindows.TaskList
        Dim TLItem As TaskItem

        For i = 1 To TL.TaskItems.Count
            TLItem = TL.TaskItems.Item(i)
            Try
                DTE.Debugger.Breakpoints.Add("", TLItem.FileName, TLItem.Line)
            Catch ex As Exception
                ' breakpoints can't be added everywhere
            End Try
        Next
    End Sub
End Module

This is neat:
How do I put a breakpoint at every MessageBox in my application?

But is there a way to do this type of thing for tokens in the Task List (View menu -> Task List) as well?
For example, I have code like this:

int a=0; //RETEST this code
int b=0; //RETEST this code

In the above, RETEST is a Task List token; is there a way to set a breakpoint on all lines matching a certain Task List token quickly without having to go to each line where the token was found?

UPDATE

Here is the macro (inspired by How do I add Debug Breakpoints to lines displayed in a "Find Results" window in Visual Studio):

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.IO
Imports System.Text.RegularExpressions

Public Module CustomMacros
    Sub SetBreakpointsUsingTaskList()

        Dim TL As TaskList = DTE.ToolWindows.TaskList
        Dim TLItem As TaskItem

        For i = 1 To TL.TaskItems.Count
            TLItem = TL.TaskItems.Item(i)
            Try
                DTE.Debugger.Breakpoints.Add("", TLItem.FileName, TLItem.Line)
            Catch ex As Exception
                ' breakpoints can't be added everywhere
            End Try
        Next
    End Sub
End Module

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

软的没边 2024-08-25 23:56:16

不幸的是,Visual Studio 中不存在这样的预装功能。可能可以使用宏来完成。

Unfortunately no such precanned functionality exists in Visual Studio. It would likely be possible to do with a Macro.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文