ProjectItemsEvents.ItemAdded:如何发现项目类型?

时间:2017-07-25 22:23:23

标签: c# .net vs-extensibility vspackage

我开始开发VSPackage并且想知道何时向项目添加新引用但订阅ProjectItemsEvents的ItemAdded会给我一个ProjectItem对象而我不知道如何检查是否这是一个参考。有人可以帮我解决这个问题吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

幸运的是我发现类VSLangProj.ReferencesEvents触发了我需要的ReferenceAdded事件。所以,我做完了:

private static ReferencesEvents _refEvents;
private static Events2 _dteEvents;
public void SubscribeEvents()
{
 EnvDTE.DTE dte = (EnvDTE.DTE)ServiceProvider.GetService(typeof(EnvDTE.DTE));
 _dteEvents = dte.Events as Events2;
 _refEvents = (ReferencesEvents)_dteEvents.GetObject("CSharpReferencesEvents");
 _refEvents.ReferenceAdded += new _dispReferencesEvents_ReferenceAddedEventHandler(ReferenceAdded);
}

private void ReferenceAdded(Reference pReference)
{
  // do some stuff.
}