如果新版本不可用,.NET 应用程序中的 assemblyBinding 可与旧版本一起使用吗?

发布于 2024-08-17 04:09:25 字数 397 浏览 2 评论 0原文

我已经为我的应用程序中使用的较新版本的程序集指定了程序集绑定,并且效果很好。

然而,在我的一台客户端计算机上,该程序集的新版本丢失了,但旧版本却存在。当我尝试运行该应用程序时,它说找不到新版本,我想这是正常的。问题是,如果新版本不可用,我如何告诉 .NET 框架使用旧版本?

目的是拥有一个独特的配置文件,该文件可以根据任何客户端计算机上安装的程序集版本自动工作。我想要一个独特的配置文件,其工作方式如下:

  • 如果引用的程序集有版本 1,则使用该版本 1。
  • 如果引用的程序集有版本 2,则使用该版本 2
  • 。...等等

我试图避免在运行时修改 assemblyBinding 信息,具体取决于所引用程序集的安装版本。

有什么想法吗? 谢谢。

I've specified an assembly binding for a newer version of an assembly used in my app, and works great.

However, on one of my client machines, the new version of that assembly is missing, but instead the old one is present. When I try to run the app, it says it cannot find the new version, which is normal, I guess. The question is, how can I tell the .NET framework to use back the old version if the new version is not available?

The purpose is to have a unique config file that works automatically depending of the assembly version installed on any client machine. I want to have a unique configuration file, that works like this:

  • if referenced assembly has version 1, than use that version 1.
  • if referenced assembly has version 2, than use that version 2.
  • ... etc

I'm trying to avoid to modify the assemblyBinding information at runtime, depending of the installed version of that referenced assembly.

Any ideas?
Thanks.

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

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

发布评论

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

评论(1

若水微香 2024-08-24 04:09:25

您必须在运行时使用 Assembly.Load 或类似的方法加载程序集。 .NET 程序集重定向不支持 if 语句和后备以及类似的东西。

You'd have to load the assembly at runtime using Assembly.Load or something along those lines. The .NET assembly redirection doesn't have support for if statements and fallbacks and things like that.

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