简体   繁体   English

如何在visual studio中的c#文件中为所有行设置断点?

[英]How to set breakpoints to all lines in a c# file in visual studio?

I am working with Visual Studio 2015. 我正在使用Visual Studio 2015。

I have a big c# class file with lot of properties and methods. 我有一个很大的c#类文件,包含很多属性和方法。 I want to set breakpoints to all possible lines (set and get of properties, methods) at once. 我想立刻为所有可能的行(设置和获取属性,方法)设置断点。 How can I do that? 我怎样才能做到这一点?

You could add Debugger.Break() on the end of every single line. 您可以在每一行的末尾添加Debugger.Break() Therefore you could use the search and replace function of visual studio and replace \\n with Debugger.Break()\\n (Remember activating the regular expression option). 因此,您可以使用visual studio的搜索和替换功能,并将\\n替换为Debugger.Break()\\n (请记住激活正则表达式选项)。 This would cause the debugger to break at every single line, even though you won't have an indicated breakpoint. 这将导致调试器在每一行中断,即使您没有指示的断点。

I don't think that there's a method to add normal vs breakpoints to every single line though, due to the fact that it's quite useless, considering that you normally just step through the code with F11 . 我不认为有一种方法可以将正常vs断点添加到每一行,因为它很无用,考虑到你通常只是用F11单调试代码。

I think you are looking for this, 我想你在找这个,

steps to follow: 要遵循的步骤:

1) Add a break point on the first line of code you want to debug. 1)在要调试的第一行代码上添加断点。

2) Run the application. 2)运行应用程序。

3) When you want to run the next line of code, Select Debug | 3)如果要运行下一行代码,请选择Debug | Step Into 踏入

4) Repeat step #3 for each line of the code 4)对代码的每一行重复步骤#3

Step Into(F11) or use the Debugger.Break() or add breakpoint directly would be the workarounds for you, of course, I suggest you use the Step Into(F11) which was much more convenient. 步入(F11)或使用Debugger.Break()或直接添加断点将是你的解决方法,当然,我建议你使用Step Into(F11)这样更方便。

If you could use the latest VS2017 version, it has a new feature "Run to Click" which is also a better workaround for you during debugging. 如果你可以使用最新的VS2017版本,它有一个新功能“Run to Click”,这也是一个在调试过程中更好的解决方法。

Actually you don't have to debug every line code, that's also the reason I suggest you use this new feature. 实际上你不必调试每一行代码,这也是我建议你使用这个新功能的原因。

在此输入图像描述

Run to Click: Simply click the icon next to a line of code while debugging to run to that line. 运行到单击:只需在调试时单击代码行旁边的图标即可运行到该行。 No longer set temporary breakpoints or perform several steps to execute your code and stop on the line you want. 不再设置临时断点或执行几个步骤来执行代码并停止在您想要的行上。 Now while stopped at a break state under the debugger, the Run to Click icon subtly appears next to the line of code that your mouse is hovered over. 现在,当在调试器下停止在中断状态时,鼠标悬停在代码行旁边会巧妙地显示“运行到单击”图标。 Move your mouse to the icon and click the button, now your code will run and stop on that line the next time it is hit in your code path. 将鼠标移动到图标并单击按钮,现在您的代码将在下一次在代码路径中被命中时运行并停在该行上。 Turn it off from Debug> Options > Enable Run to Click. 从Debug> Options> Enable Run to Click中将其关闭。

Reference: 参考:

https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes

With vim (vsvim) you can set a breakpoint, move down a line, then repeat however many times you like, eg: 使用vim(vsvim),您可以设置断点,向下移动一行,然后重复多次,例如:

{Escape}qq:vsc Debug.ToggleBreakpoint{Enter}jq100@q {Escape} qq:vsc Debug.ToggleBreakpoint{Enter}jq100@q

will set breakpoints on the next 100 lines 将在接下来的100行设置断点

edit: here is example video, wouldnt let me embed gif https://imgur.com/SFhlEr7 编辑:这是示例视频,不让我嵌入gif https://imgur.com/SFhlEr7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM