OnSave Event not seen if tool window closed RRS feed

  • Question

  • I'm completely new to VS extensions.  I need hook into the OnBeforeSave event so I followed an example on the docs site which creates and RDTEventsExplorer. This all works fine if the tool window the example uses, is first opened from the View->OtherWindows menu.  It can then be closed and the events are still captured.  However, if the tool window is never opened the events are not seen.  So my question is how do I create an extension with no tool windows or menus which reacts to the OnBeforeSave event?  Where do I put the code which implements "IVsRunningDocTableEvents"?  Anyone know?
    Friday, February 14, 2020 9:30 AM


All replies

  • VS packages are typically loaded on-demand by registering your package with one or more UI contexts via the ProvideAutoLoad attribute.

    Which project or file types do you need to intercept the OnBeforeSave event for? That will dictate which UIContext(s) you'll want to register your package to load under.

    A few documentation links that'll get you pointed in the right direction.

    Also, as an aside, I've found Paul Harrington's Component Diagnostics extension invaluable in discovering UIContext guids. After installing it, you'll find a "Components Diagnostics" menu item in the VS Help menu. I regularly use the "Selection and UIContext" page to find the currently active UIContexts to ID useful contexts/conditions where I want my package(s) loaded.


    Ed Dore

    Friday, February 14, 2020 8:37 PM
  • Hi Ed, thanks for the info - more reading for me I think!

    To answer your question I'm looking to intercept the OnBeforeSave event for .CS/.CPP files so I can auto update a version string (if it exists) on the first/second line of the file.  This is followed by edit history comments in the form:

    # region History
    /* Current Version : 1.0.45
     Version : 1.0.0
     Date    : 01-01-2010
     Comment : Initial code



    • Edited by markviatech Saturday, February 15, 2020 10:02 AM
    Saturday, February 15, 2020 10:02 AM
  • Hi markviatech,

    Sorry for bothering you.

    Does ED Dore's suggestion help you implement this feature? If you have any questions about it, please feel free to contact us.

    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, February 18, 2020 10:43 AM
  • Hi Dylan

    Sorry, didn't notice I'd missed that.  Ed's answer will get me where I need to be I think having skimmed the documentation, but I haven't had chance to try the implementation yet.  So I'll mark it as the solution and post when I've got it working.



    Tuesday, February 18, 2020 6:51 PM