Macro: Toggle bookmark with breakpoint RRS feed

  • Question

  • Hey all,

    I have been unable to find an answer to my question and I'm not proficient enough with writing macros to do it myself.  Here goes:

    I would like to create a macro in Visual Studio 2005 (and newer) where hitting F9 to toggle a breakpoint also toggles a bookmark.  I will then remap my F9 key to run the macro instead of just only toggling the breakpoint.

    To be clear:

    If no breakpoint exists on the current line, add a breakpoint and bookmark.
    If a breakpoint is already on the current line, remove the breakpoint and the bookmark on that line.

    Can someone help me with this?


    Rich Moore
    Friday, February 13, 2009 9:40 PM


  • Hello Rich,

    One approach is to use the automation model (EnvDTE):

    For debugger breakpoints you can use EnvDTE.DTE.Debugger.BreakPoints.Add , etc.
    For bookmarks, given an EnvDTE.Document, you use EnvDTE.Document.Object and cast to EnvDTE.TextDocument, you get a TextPoint with TextDocument.StartPoint, create an EditPoint with TextPoint.CreateEditPoint, move it to the desired line (MoveToXXX methods) and call EditPoint.SetBookmark.

    Another approach is to call the commands (using DTE.ExecuteCommand(...) ) that VS offers in the UI:


    You can discover command names in the Tools, Options window, Environment, Keyboard section.

    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about VS extensibility: http://msmvps.com/blogs/carlosq/
    • Proposed as answer by Carlos J. Quintero Monday, February 16, 2009 9:35 AM
    • Marked as answer by Rich Moore Monday, February 16, 2009 5:37 PM
    Monday, February 16, 2009 9:34 AM