基于 .NET 4 构建的 MEF 应用程序是否可以导入针对 .NET 3.5 构建的类型?

发布于 2024-09-13 01:05:45 字数 234 浏览 2 评论 0原文

我正在使用托管扩展性框架开发一个主机应用程序,它是针对 .NET 4 和框架中内置的 System.ComponentModel.Composition 程序集构建的。我希望支持使用 .NET 3.5 开发部件并以声明方式导出它们的能力。

由于导出属性是 .NET 4 中的新增属性,因此无法被 .NET 3.5 程序集引用,因此我不确定导出部件的最佳方法。有没有一种简单的方法可以做到这一点,而无需实现使用其他机制来发现导出的新型目录?

I am developing a host application using Managed Extensibility Framework and it's built against .NET 4 and the System.ComponentModel.Composition assembly that is built into the framework. I would like to support the ability to develop parts using .NET 3.5 and export them declaratively.

Since the export attributes are new in .NET 4 and thus cannot be referenced by the .NET 3.5 assembly, I'm not sure the best way to go about exporting parts. Is there an easy way to do this without implementing a new type of catalog that uses some other mechanism for discovering exports?

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

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

发布评论

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

评论(2

何以畏孤独 2024-09-20 01:05:45

您可以为 AppDomain.AssemblyResolve 编写一个处理程序当请求 3.5 版本时,将返回 .NET 4 版本的 MEF。但是,您编写的处理程序仅在无法使用默认绑定逻辑找到程序集时才会使用,因此您需要确保 3.5 MEF DLL 不可用,或者可能在没有上下文的情况下加载扩展程序集( 请参阅此处)以防止其解析为该 DLL。

You can write a handler for AppDomain.AssemblyResolve that will return the .NET 4 version of MEF when the 3.5 version is requested. However, the handler you write will only be used if it can't find the assembly using the default binding logic, so you would need to make sure the 3.5 MEF DLL wasn't available, or possibly load the extension assemblies with no context (see here) to prevent it from resolving to that DLL.

累赘 2024-09-20 01:05:45

您也许可以使用程序集绑定重定向 针对 .NET 3.5 版本的 MEF 编译扩展,但让它们在运行时使用 .NET 4 版本。

You might be able to use an Assembly Binding Redirect to have the extensions compiled against a .NET 3.5 version of MEF but have them use the .NET 4 version at runtime.

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