如何为 MEF 组件提供 API 存根?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过创建两个程序集解决了这个问题:
[Export]
。[Export]
。使用我的功能的人只需引用前者,并将“复制本地”和“精确版本”设置为 false。
I solved this problem by creating two assemblies:
[Export]
s in here.[Export]
s.People using my feature just reference the former, and set Copy Local and Exact Version to false.