具有后备版本的参考 GAC 组件
我的项目引用了 GAC 中程序集的 2.0.0.0 版本。如果版本 2.0.0.0 不可用,我想重定向/更改对版本号 1.0.0.0 的引用。
一些研究提出了以下帖子,但它们似乎与我的场景没有直接关系:
如何提供后备程序集而不是无法加载的程序集?
如何引用多版本程序集
我相信强名称程序集需要特定的版本号,所以我认为引用本身不能使用通配符(*)?解决我的场景的最简单方法是什么?
My project references version 2.0.0.0 of an assembly in the GAC. If version 2.0.0.0 is not available, I'd like to redirect/change the reference to version number 1.0.0.0.
Some research came up with the following posts, but they don't seem to be directly related to my scenario:
How to provide a fallback assembly instead of the one that can't be loaded?
How to reference to multiple version assembly
I believe that strongly-named assemblies required a specific version number, so I don't think the reference itself can use wildcard (*)? What is the simpliest way to solve my scenario?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案是使用绑定重定向。显然,如果旧版本高于新版本,它就会起作用,就像我的场景一样。
http://www.infosysblogs.com/microsoft/2007/04/loading_multiple_versions_of_s.html
无需更改代码 - 添加简单的配置。
The solution is to use a bindingRedirect. Apparently it works if the oldVersion is higher than the newVersion, as in my scenario.
http://www.infosysblogs.com/microsoft/2007/04/loading_multiple_versions_of_s.html
No code changes - simple config addition.
如果需要动态加载任意程序集和类,可以使用
Assembly.Load
(或其变体之一)和Assembly.CreateInstance()
。您需要这样做的原因是它允许后期绑定。在 GAC 中引用程序集是一种早期绑定方案,并且无法在运行时进行更改。
If you need to dynamically load arbitrary assemblies and classes, you can use
Assembly.Load
(or one of its variations) andAssembly.CreateInstance()
.The reason you need to do it this way is it allows late binding. Referencing an assembly in the GAC is an early binding scenario, and cannot be changed as such at runtime.