Reputation: 117
This question was answered before for a previous version of Visual Studio (VS). The offered solutions involved macros, which are no longer available in VS 2015. Could I get a solution for VS 2015?
I would like to do a "find all" in VS and put a debug-breakpoint on every line with a find match.
Link to previous question asked by Noah: How do I add Debug Breakpoints to lines displayed in a "Find Results" window in Visual Studio
Upvotes: 6
Views: 2705
Reputation: 159
If you have JetBrains Resharper and use one of Reharper's search commands, you can do this directly from Resharper's Find Results window (different from VS Find Results).
Example:
Resharper > Navigate > Go to Text... (Ctrl+T,T,T if using Resharper key map)
And then in Find Results (Resharper), right click any node or container in the tree view and choose "Set Breakpoint." This sets a breakpoint on all sub-nodes.
Reference:
https://blog.jetbrains.com/dotnet/2017/12/04/debugger-features-resharper/
Upvotes: 4
Reputation: 27960
I've converted the old macro to a VB command in Visual Commander (by adding explicit namespaces to classes):
Public Class C
Implements VisualCommanderExt.ICommand
Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
Dim findResultsWindow As EnvDTE.Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindFindResults1)
Dim selection As EnvDTE.TextSelection
selection = findResultsWindow.Selection
selection.SelectAll()
Dim findResultsReader As New System.IO.StringReader(selection.Text)
Dim findResult As String = findResultsReader.ReadLine()
Dim findResultRegex As New System.Text.RegularExpressions.Regex("(?<Path>.*?)\((?<LineNumber>\d+)\):")
While Not findResult Is Nothing
Dim findResultMatch As System.Text.RegularExpressions.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 System.Exception
' breakpoints can't be added everywhere
End Try
End If
findResult = findResultsReader.ReadLine()
End While
End Sub
End Class
Upvotes: 11