如何为 MEF 组件提供 API 存根?

发布于 2024-08-12 12:24:15 字数 454 浏览 1 评论 0原文

Visual Studio 2010 SDK 附带了许多程序集,例如 Microsoft.VisualStudio.Text.Data 和 Microsoft.VisualStudio.Text.UI,它们只是存根。要为 Visual Studio 编写扩展,请引用这些程序集,但将引用的“复制本地”和“精确版本”属性设置为 false。当您的扩展加载到 Visual Studio 中时,引用将绑定到 Visual Studio 先前加载的这些程序集的内部实现。

我想提供一个新的 MEF 导出组件,该组件充当其他 MEF 包可以[Import] 的 Visual Studio 服务。要使用该服务,其他组件需要引用我的包 - 但我更喜欢它们引用存根,这样我就可以更改服务的内部实现,而不会破坏引用它的其他包。如何提供一个“存根”程序集,其中包含来自某个任意程序集的公开可见的 API 组件,这样,如果您引用该存根,它将在运行时与提供的实现无缝协作?

The Visual Studio 2010 SDK ships with many assemblies like Microsoft.VisualStudio.Text.Data and Microsoft.VisualStudio.Text.UI that are just stubs. To write an extension for Visual Studio, you reference these assemblies, but set "Copy Local" and "Exact Version" properties of the references to false. When your extension is loaded in Visual Studio, the references are bound to Visual Studio's previously loaded internal implementation of these assemblies.

I'd like to provide a new MEF exported component that acts as a Visual Studio service that other MEF packages can [Import]. To use the service, the other components will need to reference my package - but I prefer for them to reference a stub so I can make changes to the internal implementation of my service without breaking other packages that reference it. How can I provide a "stub" assembly containing the publicly visible API components from some arbitrary assembly, such that if you reference the stub it will seamlessly work with the provided implementation at runtime?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神魇的王 2024-08-19 12:24:15

我通过创建两个程序集解决了这个问题:

  • MyCompany.VisualStudio.Feature:接口和某些情况下的抽象类以简化最常见的实现。这里没有[Export]
  • MyCompany.VisualStudio.Feature.Implementation:实现与功能相关的服务。在这里您将看到[Export]

使用我的功能的人只需引用前者,并将“复制本地”和“精确版本”设置为 false。

I solved this problem by creating two assemblies:

  • MyCompany.VisualStudio.Feature: Interfaces and in some cases abstract classes to simplify the most common implementations. No [Export]s in here.
  • MyCompany.VisualStudio.Feature.Implementation: Implements services related to the feature. Here you'll see the [Export]s.

People using my feature just reference the former, and set Copy Local and Exact Version to false.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文