'How to set breakpoints to all lines in a c# file in visual studio?

I am working with Visual Studio 2015.

I have a big c# class file with lot of properties and methods. I want to set breakpoints to all possible lines (set and get of properties, methods) at once. How can I do that?



Solution 1:[1]

You could add Debugger.Break() on the end of every single line. 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). 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.

Solution 2:[2]

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.

2) Run the application.

3) When you want to run the next line of code, Select Debug | Step Into

4) Repeat step #3 for each line of the code

Solution 3:[3]

With vim (vsvim) you can set a breakpoint, move down a line, then repeat however many times you like, eg:

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

will set breakpoints on the next 100 lines

edit: here is example video, wouldnt let me embed gif https://imgur.com/SFhlEr7

Solution 4:[4]

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.

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.

Actually you don't have to debug every line code, that's also the reason I suggest you use this new feature.

enter image description here

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.

Reference:

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

Solution 5:[5]

Open a feature request with Microsoft https://docs.microsoft.com/en-us/visualstudio/ide/suggest-a-feature?view=vs-2022

There should be a mode that visual studio can be put in so that it automatically stops on every line of code in a particular project. This would be VERY valuable when you attach the debugger to a pre-existing process and you don't know where in the app is the current point of execution is, ie: web apps where you do not know the entry point.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MetaColon
Solution 2 Sajeetharan
Solution 3 dog
Solution 4 Jack Zhai-MSFT
Solution 5 trevorcroft