.NET 程序集绑定
我有一个 api MyApi,它由应用程序 MyApplication 使用。
MyApi 有几个针对 .NET 4.0 Client Profile 的 dll。例如:
- MyApi.Core
- MyApi.Domain
- MyApi.Providers
(以及更多)
为了简化部署,这些都被 ILMerged 到
- MyApi.ClientProfile
所有 MyApis dll 都是强命名的。
MyApplication 中的所有项目都引用 MyApi.ClientProfile。
我现在正在向 MyApi 添加一些 Web 功能,因此我添加了一个 dll MyApi.Web,它面向 .NET 4.0 扩展配置文件。 MyApi.Web 引用 MyApi.Core 和 MyApi.Domain(以及 System.Web dll)。
现在还有一个 MyApplication.Web 项目。它引用了 MyApplication 中的一些其他项目(其中引用了 MyApi.ClientProfile dll)。 MyApplication.Web项目需要引用MyApi.Web dll。
我该怎么做?
如果我从 MyApplication.Web 添加对 MyApi.Core 和 MyApi.Domain 的引用,则 MyApplication.Web 的多个程序集中将存在类型。
如果我不从 MyApplication.Web 添加对 MyApi.Core 和 MyApi.Domain 的引用,MyApi.Web 将无法加载,因为它找不到 MyApi.Core 或 MyApi.Domain (因为仅存在 MyApi.ClientProfile)。
我无法处理程序集解析事件并将 MyApi.Core/MyApi.Domain 的请求重定向到 MyApi.ClientProfile,因为 MyApi 程序集都是强命名的,这将使其失败。
我无法将 MyApi.Web 合并到 MyApi.ClientProfile 中,因为 .NET 4.0 客户端配置文件应该支持 MyApi.ClientProfile (并且 MyApi.Web 引用了 System.Web 等)。
如果我将 MyApi.Web 更改为引用 MyApi.ClientProfile,这应该适用于这种情况,但并不理想,因为它不适用于直接引用 MyApi.Core 和 MyApi.Domain 的另一个应用程序。
我不想强制 MyApplication.Web 在其配置中指定bypassTrustedAppStrongNames(认为直接从 MyApi.Web 启用此设置可能是一个可接受的选项......)。
所以,我一直在思考一个合适/优雅的解决方案来解决这个问题。
有什么建议吗?
谢谢。
I have an api, MyApi, which is consumed by an application, MyApplication.
MyApi has several dlls targeted to the .NET 4.0 Client Profile. For example:
- MyApi.Core
- MyApi.Domain
- MyApi.Providers
(and some more)
For deployment simplicity, these are ILMerged into
- MyApi.ClientProfile
All of the MyApis dlls are strong named.
All the projects in MyApplication reference MyApi.ClientProfile.
I'm now adding some web functionality into MyApi, so I've added a dll MyApi.Web, which is targeted to the .NET 4.0 Extended Profile. MyApi.Web references MyApi.Core and MyApi.Domain (as well as System.Web dlls).
There is now also a MyApplication.Web project. It references some other projects in MyApplication (which have references to the MyApi.ClientProfile dll). The MyApplication.Web project needs to reference MyApi.Web dll.
How can I do this?
If I add references to MyApi.Core and MyApi.Domain from MyApplication.Web, then there will be types that exists in multiple assemblies for MyApplication.Web.
If I don't add references to MyApi.Core and MyApi.Domain from MyApplication.Web, MyApi.Web will fail to load because it can't find MyApi.Core or MyApi.Domain (because only MyApi.ClientProfile is present).
I can't handle the assembly resolve event and redirect requests for MyApi.Core/MyApi.Domain to MyApi.ClientProfile because the MyApi assemblies are all strong named and that will make it fail.
I can't merge MyApi.Web into the MyApi.ClientProfile because MyApi.ClientProfile should be supported for the .NET 4.0 Client Profile (and MyApi.Web has references to System.Web, etc.).
If I change MyApi.Web to reference MyApi.ClientProfile, that should work for this one case, but isn't ideal, because it won't work for another application references MyApi.Core and MyApi.Domain directly.
I don't want to force MyApplication.Web to specify bypassTrustedAppStrongNames in its config (thought enabling this setting somehow from MyApi.Web directly might be an acceptable option....).
So, I'm stuck thinking of a suitable/elegant solution to this problem.
Any suggestions?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到:
如果您的程序集具有相同的公钥令牌,则可以进行重定向,并且名称并不重要。
因此,因为 MyApi.Client 配置文件使用与 MyApi.Core 相同的密钥进行签名,所以如果我在 MyApi.Web 中处理 AssemblyResolve,我实际上可以告诉它使用 MyApi.ClientProfile 而不是 MyApi.Core。
我本以为它会引发强名称验证错误。它不......因为公钥是相同的。
I came to a realization:
If your assemblies have the same Public Key Token, you can do redirection and the name doesn't matter.
So, because MyApi.Client profile is signed with the same key as MyApi.Core, if I handle AssemblyResolve in MyApi.Web, I actually CAN tell it to use MyApi.ClientProfile instead of MyApi.Core.
I would have thought it would throw a strong name verification error. It does not....because the public keys are the same.