Second Life of a Hungarian SharePoint Geek

July 15, 2012

Automatically setting the next statement to a specific position when debugging in Visual Studio

Filed under: Debugging, Macros, Tips & Tricks, Visual Studio — Tags: , , , — Peter Holpar @ 21:58

Have you ever faced to the problem during debugging in Visual Studio, that you find a problem in a code block, and would like to avoid this code without altering the code and rebuilding / restarting  the application? In this case you need to set the next statement to a specific line of code using the context menu (see below).

image

It is trivial when you need to do it just  a few time, but it can be rather tedious, if not impossible, if you are – for example – in a loop processing several hundreds of items, and should do it for each items.

Fortunately, it is easy to achieve this goal using Visual Studio macros. The following method – defined in a module called in this example DebugHelpers – jumps to the next bookmark, and sets the next statement to that position.

Sub GoToNextBookmark()
    DTE.ExecuteCommand("Edit.NextBookmark")
    DTE.ExecuteCommand("Debug.SetNextStatement")
End Sub

Having this method, all you need to do is to set a new breakpoint with When Hit… option at the line of code you want to jump from,

image

and set the GoToNextBookmark method in the Run a macro list:

image

Then mark the target of the jump with a bookmark, and you are ready.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.