vsct listen for ProjectItemsEvents.ItemAdded not catching anything

110 views Asked by At

VS2019 16.5.0 preview 1

I'm trying to catch events when a project has an item added, deleted, or renamed.

I am catching when the solution is opened and closed, or when a project is added or removed, but I am just not catching when a single file is added to a project.

public DTE2 _dte2;
private Events2 _events2;
private SolutionEvents _SolutionEvents;
private ProjectItemsEvents _ProjectItemsEvents;

public MyProject()
{
    _dte2 = Package.GetGlobalService(typeof(EnvDTE.DTE)) as DTE2;

    _dte2.Events.SolutionEvents.AfterClosing += SolutionEvents_AfterClosing;
    _dte2.Events.SolutionEvents.Opened += SolutionEvents_Opened;
    _dte2.Events.SolutionEvents.ProjectAdded += SolutionEvents_ProjectAdded;
    _dte2.Events.SolutionEvents.ProjectRemoved += SolutionEvents_ProjectRemoved;
    _dte2.Events.SolutionEvents.BeforeClosing += SolutionEvents_SolutionBeforeClosing;
    _dte2.Events.SolutionEvents.ProjectRenamed += SolutionEvents_ProjectRenamed;

    _events2 = (Events2)_dte.Events;
    _ProjectItemsEvents = _events2.ProjectItemsEvents;

    _events2.ProjectItemsEvents.ItemAdded += ItemAddedHandler;
    _events2.ProjectItemsEvents.ItemRemoved += ItemRemovedHandler;
    _events2.ProjectItemsEvents.ItemRenamed += ItemRenamedHandler;
}

private void ItemAddedHandler(ProjectItem projectItem) 
{
} <- breakpoint here

private void ItemRemovedHandler(ProjectItem projectItem)
{
} <- breakpoint here

private void ItemRenamedHandler(ProjectItem projectItem, string oldName)
{
} <- breakpoint here

Putting breakpoints on the ItemAddedHandler, ItemRemovedHandler, or ItemRenamedHandler has no effect at all. These methods never get called when I add, rename, or delete a file from a project when the extension is running in the experimental instance.

I found references to other people having similar problems but these were all related to garbage collection, and I don't believe this is my problem as I have a reference to the events2 and projectItemsEvents.

0

There are 0 answers