eventsvisual-studio-2012envdteprojectitem

ItemAdded Event in Visual Studio: Get item AND project


I develop a tool, which recognize changes made in a Visual Studio solution. Therefore, I use dte Events like

solutionEvents.ProjectRemoved += cV.OnProjectRemoved;
solutionEvents.ProjectRenamed += cV.OnProjectRenamed;
projectItemsEvents.ItemAdded += cV.OnItemAdded;

But no I have the problem, that the onItemAdded Event only returns the added Item (or the full path by getting the properties), but not the project where it has been added.

First I thought about using the full path to identify the project, but this doesn't work if you add an existing item from another folder to the project.

Is there any possibility or maybe another event available to get the added Item and the project where it has been added?

Thank you in advance!


Solution

  • At least I found the answer. The projectItemsEvents.ItemAdded method gets the ProjectItem which has been added as input. That item has another property:

    ProjectItem.ContainingProject.Name 
    

    That is how I get the name of the project, where I added the item.