How Do I Add Debug Breakpoints To Lines Displayed In A "Find Results" Window In Visual Studio
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?
This answer does not work for Visual Studio 2015 or later. A more recent answer can be found here.
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
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.
- → React Native with visual studio 2015 IDE
- → Where to find example Visual Studio 2015 project(s) using typescript and React?
- → How to configure Visual Studio 2015 to write JSX in ASP.NET 5 (RC) with intellisense
- → How to make this simple TypeScript + React app work with Visual Studio 2015?
- → Format liquid(Shopify) code in visual studio code
- → Typescript intellisense without emitting require
- → How to display shopify free them output on my laptop using visual studio code?
- → Visual Studio Code - how to debug node.js routes?
- → Visual Studio cordova, simple way to "live reload" on Android devices?
- → --allow-live terminal command for shopify development
- → compile typescript with a visual studio code task, specifying the output directory
- → How to highlight all symbol appearances in python code with PTVS?
- → What is the location of the Python tools for Visual Studio?