C# 如何使用应用程序配置文件重定向程序集加载
我的程序集在 GAC 中注册的版本很少。现在,我希望我的一个使用此程序集(版本 1.3)的客户端指向最新版本(1.4),而无需打开源代码并重新编译客户端。
我看到一篇文章演示了使用应用程序配置文件(winform 应用程序)执行此操作的技术,
这里是配置文件内容:
<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:asm="urn:schemas-microsoft-com:asm.v1">
<runtime>
<asm:assemblyBinding>
<!-- one dependentAssembly per unique assembly name -->
<asm:dependentAssembly>
<asm:assemblyIdentity
name="MyFacade"
publicKeyToken="c9c18e16df1654e0" />
<!-- one bindingRedirect per redirection -->
<asm:bindingRedirect oldVersion="1.3.0.0"
newVersion="1.4.0.0" />
</asm:dependentAssembly>
</asm:assemblyBinding>
</runtime>
</configuration>
如您所见,有一个从版本 1.3.0.0
到 < code>1.4.0.0 用于名为 MyFacade
的程序集。
现在,这种方法只有一个小问题。它不起作用:)
我确信这与我的代码有关。
有什么建议吗?
谢谢,
阿迪巴尔达
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,这是最好的来源< /a> 我发现了这个主题。存在一些差异,例如,它们不使用
asm:
命名空间,此外,您可能希望通过添加 来禁用发布者策略;
如文章中所述。在我们之前做的项目中,我们需要更多的控制,因此我们需要捕获AppDomain.AssemblyResolve 事件 并路由到我们想要的任何程序集。 此处您可以找到有关该概念的更多信息。不过,您必须操作您的应用程序一次。
first, this is the best source I've found about this subject. There are some differences, for example, they are not using the
asm:
namespace, and also, you might want to disable the publisher policy by adding<publisherPolicy apply="no" />
as described in the article.In a previous project we did, we needed even more control, so we needed to catch the AppDomain.AssemblyResolve Event and route to any assembly we wanted. Here you can find more informations about the concept. You'd have to manipulate your app once, though.