How can I listen to ProjectItem removal via DTE?

I have a designer who relies on the existence of other elements of a solution. If one of these elements is deleted, the designer fails, and you need to edit it as XML to fix it. Not quite comfortable.

However, I have a DTE object representing an instance of Visual Studio, as well as ProjectItems that I am dependent on.

Is it possible, somewhere in the depths of the DTE, to register a listener to remove this ProjectItem? And if so, how would I do that?

+3
source share
2 answers

, . , .

Events2 events2 = dte.Events as Events2;
if (events2 != null)
{
    this.projectItemsEvents = events2.ProjectItemsEvents;
    this.projectItemsEvents.ItemAdded += this.ProjectItemsEvents_ItemAdded;
    this.projectItemsEvents.ItemRemoved += this.ProjectItemsEvents_ItemRemoved;
    this.projectItemsEvents.ItemRenamed += this.ProjectItemsEvents_ItemRenamed;
}

this.csharpProjectItemsEvents =
    dte.Events.GetObject("CSharpProjectItemsEvents") as ProjectItemsEvents;
if (this.csharpProjectItemsEvents != null)
{
    this.csharpProjectItemsEvents.ItemAdded += this.CSharpProjectItemsEvents_ItemAdded;
    this.csharpProjectItemsEvents.ItemRemoved += this.CSharpProjectItemsEvents_ItemRemoved;
    this.csharpProjectItemsEvents.ItemRenamed += this.CSharpProjectItemsEvents_ItemRenamed;
}

, . , , .

private ProjectItemsEvents projectItemsEvents;
private ProjectItemsEvents csharpProjectItemsEvents;
+3

, , ProjectItems ( ItemDeleted).

+1

Source: https://habr.com/ru/post/1745507/


All Articles