如何将调试断点添加到“查找结果"窗口中显示的行中? Visual Studio中的窗口 [英] How do I add Debug Breakpoints to lines displayed in a "Find Results" window in Visual Studio

查看:120
本文介绍了如何将调试断点添加到“查找结果"窗口中显示的行中? Visual Studio中的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2005-2015中,可以找到包含某些引用的所有行,并将其显示在查找结果"窗口中.

In Visual Studio 2005-2015 it is possible to find all lines containing certain references and display them in a "Find Results" window.

现在显示了这些结果行,是否有任何键盘快捷方式可以允许向所有这些调试点添加调试断点?

Now that these result lines are displayed, is there any keyboard shortcut that would allow adding debug breakpoints to all of them?

推荐答案

此答案不适用于Visual Studio 2015或更高版本.可以在您可以使用Visual Studio宏轻松地做到这一点.在Visual Studio中,按Alt-F11打开Macro IDE,然后通过右键单击MyMacros并选择添加" |添加模块..."来添加新模块.

You can do this fairly easily with a Visual Studio macro. Within Visual Studio, hit Alt-F11 to open the Macro IDE and add a new module by right-clicking on MyMacros and selecting Add|Add Module...

在源代码编辑器中粘贴以下内容:

Paste the following in the source editor:

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

Public Module CustomMacros
    Sub BreakpointFindResults()
        Dim findResultsWindow As Window = DTE.Windows.Item(Constants.vsWindowKindFindResults1)

        Dim selection As TextSelection
        selection = findResultsWindow.Selection
        selection.SelectAll()

        Dim findResultsReader As New StringReader(selection.Text)
        Dim findResult As String = findResultsReader.ReadLine()

        Dim findResultRegex As New Regex("(?<Path>.*?)\((?<LineNumber>\d+)\):")

        While Not findResult Is Nothing
            Dim findResultMatch As Match = findResultRegex.Match(findResult)

            If findResultMatch.Success Then
                Dim path As String = findResultMatch.Groups.Item("Path").Value
                Dim lineNumber As Integer = Integer.Parse(findResultMatch.Groups.Item("LineNumber").Value)

                Try
                    DTE.Debugger.Breakpoints.Add("", path, lineNumber)
                Catch ex As Exception
                    ' breakpoints can't be added everywhere
                End Try
            End If

            findResult = findResultsReader.ReadLine()
        End While
    End Sub
End Module

此示例在查找结果1"窗口中使用结果;您可能要为每个结果窗口创建一个单独的快捷方式.

This example uses the results in the "Find Results 1" window; you might want to create an individual shortcut for each result window.

您可以通过以下方法创建键盘快捷键:转到工具" |选项" ...,然后在左侧导航栏中的"环境"部分下选择"键盘".选择您的宏,然后分配您想要的任何快捷方式.

You can create a keyboard shortcut by going to Tools|Options... and selecting Keyboard under the Environment section in the navigation on the left. Select your macro and assign any shortcut you like.

您还可以将宏添加到菜单或工具栏,方法是转到工具" |自定义...",然后在左侧导航栏中选择"<宏>宏"部分.在列表中找到宏后,可以将其拖动到任何菜单或工具栏,在其中可以将其文本或图标自定义为所需的任何内容.

You can also add your macro to a menu or toolbar by going to Tools|Customize... and selecting the Macros section in the navigation on the left. Once you locate your macro in the list, you can drag it to any menu or toolbar, where it its text or icon can be customized to whatever you want.

这篇关于如何将调试断点添加到“查找结果"窗口中显示的行中? Visual Studio中的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆