【问题标题】:C# How to redirect assembly loading using application config fileC#如何使用应用程序配置文件重定向程序集加载
【发布时间】:2011-02-25 22:22:00
【问题描述】:

我有一个在 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>

如您所见,对于名为 MyFacade 的程序集,存在从版本 1.3.0.01.4.0.0 的绑定重定向。

现在,这种方法只有一个小问题。它不起作用:)

我确定这与我的代码有关。

有什么建议吗?

谢谢,
阿迪巴尔达

【问题讨论】:

  • 使用 fuslogvw.exe 查看 CLR 正在考虑什么。

标签: c# winforms versioning gac app-config


【解决方案1】:

首先,this is the best source我发现了这个主题。存在一些差异,例如,它们没有使用asm: 命名空间,而且您可能希望通过添加&lt;publisherPolicy apply="no" /&gt; 来禁用发布者策略,如文章中所述。

在我们之前的项目中,我们需要更多的控制,因此我们需要捕获AppDomain.AssemblyResolve Event 并路由到我们想要的任何装配体。 Here 你可以找到更多关于这个概念的信息。不过,您必须操作您的应用一次。

【讨论】:

    猜你喜欢
    • 2018-08-23
    • 2014-12-26
    • 2012-08-13
    • 2017-09-26
    • 2014-08-02
    • 1970-01-01
    • 2021-09-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多