Visual studio 如何将调试断点添加到显示在";中的行;“查找结果”;VisualStudio中的窗口
在Visual Studio 2005-2015中,可以找到包含某些引用的所有行,并在“查找结果”窗口中显示它们Visual studio 如何将调试断点添加到显示在";中的行;“查找结果”;VisualStudio中的窗口,visual-studio,debugging,breakpoints,Visual Studio,Debugging,Breakpoints,在Visual Studio 2005-2015中,可以找到包含某些引用的所有行,并在“查找结果”窗口中显示它们 现在显示了这些结果行,是否有允许向所有结果行添加调试断点的键盘快捷键?如果可以精确搜索单词,则可以使用一对键盘快捷键快速搜索 工具->选项->环境->键盘 Edit.GoToFindResults1NextLocation EditorContextMenus.CodeWindow.Breakpoint.InsertBreakpoint 将它们指定为Control+Alt+F11
现在显示了这些结果行,是否有允许向所有结果行添加调试断点的键盘快捷键?如果可以精确搜索单词,则可以使用一对键盘快捷键快速搜索 工具->选项->环境->键盘
- Edit.GoToFindResults1NextLocation
- EditorContextMenus.CodeWindow.Breakpoint.InsertBreakpoint
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
导入系统
导入System.IO
导入System.Text.RegularExpressions
进口环境
进口环境80
进口EnvDTE90
导入系统。诊断
公共模块自定义宏
子断点FindResults()
Dim FINDRESULT SWINDOW As Window=DTE.Windows.Item(常量.vsWindowKindFindResults1)
将选择设置为文本选择
selection=findResultsWindow.selection
selection.SelectAll()
Dim findResultsReader作为新的StringReader(selection.Text)
Dim findResult As String=findResultsReader.ReadLine()
Dim findResultRegex作为新的正则表达式((?*?\(?\d+):)
虽然找不到结果,但结果一文不值
Dim findResultMatch As Match=findResultRegex.Match(findResult)
如果findResultMatch.成功,那么
Dim path As String=findResultMatch.Groups.Item(“路径”).Value
Dim LINENNUMBER As Integer=Integer.Parse(findResultMatch.Groups.Item(“LINENNUMBER”).Value)
尝试
DTE.Debugger.Breakpoints.Add(“”,路径,行号)
特例
'断点不能到处添加
结束尝试
如果结束
findResult=findResultsReader.ReadLine()
结束时
端接头
端模块
本例使用“查找结果1”窗口中的结果;您可能希望为每个结果窗口创建一个单独的快捷方式
您可以通过转到“工具|选项”创建键盘快捷键。。。并在左侧导航的环境部分下选择键盘。选择宏并指定所需的任何快捷方式
您还可以通过进入“工具”|自定义…将宏添加到菜单或工具栏中。。。并选择左侧导航中的宏部分。在列表中找到宏后,可以将其拖动到任何菜单或工具栏,在那里可以根据需要自定义其文本或图标。我需要类似的功能来禁用所有断点,并在每个“Catch ex as Exception”上放置断点。但是,我对它进行了一些扩展,这样它将在您选择的字符串的每次出现时都放置一个断点。您所需要做的就是突出显示要在其上设置断点的字符串并运行宏
Sub BreakPointAtString()
Try
DTE.ExecuteCommand("Debug.DisableAllBreakpoints")
Catch ex As Exception
End Try
Dim tsSelection As String = DTE.ActiveDocument.Selection.text
DTE.ActiveDocument.Selection.selectall()
Dim AllText As String = DTE.ActiveDocument.Selection.Text
Dim findResultsReader As New StringReader(AllText)
Dim findResult As String = findResultsReader.ReadLine()
Dim lineNum As Integer = 1
Do Until findResultsReader.Peek = -1
lineNum += 1
findResult = findResultsReader.ReadLine()
If Trim(findResult) = Trim(tsSelection) Then
DTE.ActiveDocument.Selection.GotoLine(lineNum)
DTE.ExecuteCommand("Debug.ToggleBreakpoint")
End If
Loop
End Sub
希望对您有用:)保罗,非常感谢,但我有以下错误(消息框),可能是我需要重新启动电脑:
Error
---------------------------
Error HRESULT E_FAIL has been returned from a call to a COM component.
---------------------------
OK
---------------------------
我会提出下面的解决方案,它非常简单,但对我来说很有效
Sub BreakPointsFromSearch()
Dim n As Integer = InputBox("Enter the number of search results")
For i = 1 To n
DTE.ExecuteCommand("Edit.GoToNextLocation")
DTE.ExecuteCommand("Debug.ToggleBreakpoint")
Next
End Sub
F3和F9不必重新分配任何快捷方式即可执行此操作。F3转到当前面板中的下一个结果,而不是“查找结果”中的下一行。可以在“查找结果”窗格中使用F3,但还需要在“代码和结果”窗格之间单击Enter和tab。这个答案节省了很多击键次数。这仍然可能吗?我不确定点击alt F11应该显示什么,在Visual Studio 2017中找不到可以访问的宏窗口。@SweetTomato这个答案已经有近10年的历史了。我已经5年多没有使用过Visual Studio的任何变体了,但我怀疑这些变体是否还有意义。我认为新的宏需要.js