Search code examples
eventsvisual-studio-2012envdte

Execute an action on save in Visual Studio 2012


In Visual Studio 2012, I found it is possible to use DocumentSaved events from DocumentEventsClass. So I have written the following code in PowerShell.

$DTE.Events.DocumentEvents($DTE.ActiveDocument)

However, the COMObject returned is incorrect, (000... GUID). What am I doing wrong?


Solution

  • To execute an action on Save, we found that the easy solution was to set a custom tool on the file. The same way RESX files work.

    Basically, we added

    MSBuild:CustomTarget
    

    And this target will be called every time you save.