如何将调试断点添加到Visual Studio 2015的“查找结果”窗口中显示的行

时间:2016-06-27 19:19:53

标签: visual-studio visual-studio-2015

以前版本的Visual Studio(VS)之前已回答过这个问题。提供的解决方案涉及宏,这些宏在VS 2015中不再可用。我可以获得VS 2015的解决方案吗?

我想做一个"找到所有"在VS中,并使用查找匹配在每一行上放置调试断点。

链接到诺亚提出的上一个问题: How do I add Debug Breakpoints to lines displayed in a "Find Results" window in Visual Studio

2 个答案:

答案 0 :(得分:7)

我已将旧宏转换为Visual Commander中的VB命令(通过向类添加显式命名空间):

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

答案 1 :(得分:0)

如果您拥有JetBrains Resharper并使用Reharper的搜索命令之一,则可以直接从Resharper的“查找结果”窗口(与VS查找结果不同)执行此操作。

示例:

Resharper>导航>转到文本...(如果使用Resharper键映射,则为Ctrl + T,T,T)

然后在“查找结果(Resharper)”中,右键单击树视图中的任何节点或容器,然后选择“设置断点”。这将在所有子节点上设置一个断点。

enter image description here

参考:

https://blog.jetbrains.com/dotnet/2017/12/04/debugger-features-resharper/