简体   繁体   English

Visual Studio 2015解决方案资源管理器操作:UIHierarchy与IVsHierarchy

[英]Visual Studio 2015 solution explorer manipulation: UIHierarchy vs IVsHierarchy

I am building a custom VS2015 Extension (VSIX package). 我正在构建自定义VS2015扩展(VSIX程序包)。 My primary task is manipulations over the solution explorer like these: 我的主要任务是对解决方案资源管理器进行如下操作:

  1. Appending existing projects to solution 将现有项目追加到解决方案
  2. Removing projects from solution 从解决方案中删除项目
  3. Loading/unloading projects 加载/卸载项目
  4. Enumerating solution items, not only projects but also solution folders, unloaded projects, non-project items. 枚举解决方案项,不仅是项目,还包括解决方案文件夹,已卸载的项目,非项目项。

I have found some samples and most of them use one of the three common strategies: 我发现了一些样本,其中大多数使用以下三种常见策略之一:

  1. EnvDTE.Solution , EnvDTE.Project and so on. EnvDTE.SolutionEnvDTE.Project等。
  2. EnvDTE.UIHierarchy and the like. EnvDTE.UIHierarchy等。
  3. Microsoft.VisualStudio.Shell.Interop.IVsSolution and IVsHierarchy Microsoft.VisualStudio.Shell.Interop.IVsSolutionIVsHierarchy

I can see that the first one is the most poor in terms of covered scenarios. 我可以看到,就涵盖方案而言,第一个是最差的。 What I cannot figure out is the difference between the last two. 我无法弄清楚的是最后两者之间的区别。 Which one should I dive in having my tasks in mind? 在考虑任务时,我应该跳哪一个? What`s the concept behind them? 他们背后的概念是什么?

They are both interfaces implemented by the com solution object. 它们都是由com解决方案对象实现的接口。 Check out the msdns to see the difference in methods. 查看msdns以查看方法上的差异。

https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivssolution.aspx https://msdn.microsoft.com/zh-CN/library/microsoft.visualstudio.shell.interop.ivssolution.aspx

https://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivshierarchy.aspx https://msdn.microsoft.com/zh-CN/library/microsoft.visualstudio.shell.interop.ivshierarchy.aspx

UIHierarchy is an interface to the tool window (any window with nodes, not just the solution explorer) that has a hierarchy in it and comes from the VSSDK whereas the IVs interfaces are coming in directly from interop and represent the actual items in the view. UIHierarchy是工具窗口 (具有节点的任何窗口,而不仅仅是解决方案资源管理器的窗口 )的接口,该窗口中具有层次结构并来自VSSDK,而IVs接口直接来自互操作,并表示视图中的实际项。

For what you are saying the IVsSolution is the most direct interface. 对于您所说的,IVsSolution是最直接的接口。 All IVsSolutions are also IVsHierarchy but any node in the solution explorer is a hierarchy but obviously not a solution. 所有IVsSolutions也是IVsHierarchy,但是解决方案资源管理器中的任何节点都是层次结构,但显然不是解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM