在 app.config <assemblyBinding>/<codeBase> 中配置任何较新程序集版本的 .NET 程序集绑定

pal*_*ain 5 .net c# app-config .net-assembly assembly-binding-redirect

在 C# 项目中,我使用外部程序集并将其添加到项目的 References 中。假设程序集称为“ ABC ”,位于版本1.0.0.0 的编译时c:\complie-time\abc.dll。“复制本地”设置为 false。

因为它不是本地复制的,所以必须在 app.config 中指定程序集位置。

<runtime>
 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="ABC"  culture="neutral" publicKeyToken="xyz"/>
    <codeBase version="????" href="FILE://c:/ABC-install/abc.dll"/>
  </dependentAssembly>
 </assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)

ABC 程序集由 ABC 应用程序安装提供。所以在运行时,dll 位于不同的位置c:\ABC-install\abc.dll

问题是:我应该在codeBase版本中放什么?

如果用户安装ABC的新版本说1.1.0.0,它被称为是向下兼容的,上面将无法工作,因为.NET框架正在寻找版本1.0.0.0C:\ ABC安装\ ABC。 dll如果我把 1.0.0.0 放在那里。

条件是在编译时我们不知道 c:\ABC-install 中的版本号是多少。我们所知道的是它向后兼容。该项目应该能够与所有版本的 ABC 程序集一起运行。

如何配置 app.config 以允许绑定外部程序集的较新版本,但在编译时未知运行时版本,而在编译时项目是基于参考设置中的 1.0.0.0 dll 构建的?

编辑:codeBase 版本为 ???? 清楚地表明问题。