0

I want my extension to do something everytime an item gets added to the project. This works fine for normale Projects or, with some magic (see here), for the Project Type "Website". But i cant get it to work with .xproj.

Here my current code to access the ItemAdded event (shortened)

var events = _dte.Events as Events2;

_projectItemEvents = events.ProjectItemsEvents; 
_projectItemEvents.ItemAdded += ItemAdded;

_websiteItemEvents = events.GetObject ("WebSiteItemsEvents") as ProjectItemsEvents;
_websiteItemEvents.ItemAdded += ItemAdded;

_csharpItemEvents = events.GetObject ("CSharpProjectItemsEvents") as ProjectItemsEvents;
_csharpItemEvents.ItemAdded += ItemAdded;

Does anyone know how to access the ItemAdded event in case of an .xproj project type?

Edit: Edited code; The variables are all class fields and are not garbage collected, as in case of the other project types, the events are fired properly, just not in case of an .xproj.

Sosian
  • 622
  • 11
  • 28
  • 2
    IIRC DTE events are pretty vulnerable to garbage collection. You have to hold onto a reference to the event object in order to prevent this. Typically that means class-level fields on whatever class is instantiated and kept alive in your project. –  Sep 21 '16 at 15:29
  • 1
    Thats included, it just fell victim to shortened code, but you are completely right, its an important point. Sry, i thought this was implicated, as i stated that it is working correctly with other project types. I clarified the question. – Sosian Sep 22 '16 at 07:26

0 Answers0