C# 如何使用应用程序配置文件重定向程序集加载

发布于 2024-09-04 07:14:41 字数 967 浏览 1 评论 0 原文

我的程序集在 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 的程序集。

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

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

有什么建议吗?

谢谢,
阿迪巴尔达

I have an assembly with few versions registered in the GAC. Now, I want one of my clients which uses this assembly (version 1.3) to point to the newest version (1.4) without opening the source and recompiling the client.
I saw an article demonstrating a technique for doing so using the application config file (winform application)

here is the config file content :

<?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>

As you can see, there is a binding redirect from version 1.3.0.0 to 1.4.0.0 for assembly named MyFacade.

Now, there's only a Minor issue with this approach. It doesn't work :)

I'm sure it's something with my code.

Any suggestions?

Thanks,
Adi Barda

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

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

发布评论

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

评论(1

自我难过 2024-09-11 07:14:41

首先,这是最好的来源< /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.

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