【问题标题】:Configuration of .NET assembly binding of any newer assembly version in app.config <assemblyBinding>/<codeBase>在 app.config <assemblyBinding>/<codeBase> 中配置任何较新程序集版本的 .NET 程序集绑定
【发布时间】:2015-02-17 03:24:50
【问题描述】:

在 C# 项目中,我使用外部程序集并将其添加到项目的引用中。假设程序集名为 "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>

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

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

如果用户安装较新版本的 ABC 说 1.1.0.0,并且已知它是向后兼容的,那么上述将不起作用,因为 .NET 框架正在寻找版本 1.0.0.0c:\ABC-install\abc.dll 如果我把 1.0.0.0 放在那里。

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

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

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

【问题讨论】:

  • 你知道代码库和程序集重定向的区别吗?

标签: c# .net app-config .net-assembly assembly-binding-redirect


【解决方案1】:

取自标准的示例片段(我相信 Visual Studio 生成的 web.config ),使用 bindingRedirect 部分。

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>

【讨论】:

  • 它将 v1 重定向到 v2 到它具有 v2 dll 的运行时 dll 位置(例如 c:\ABC-install)。但关键是,在 c:\ABC-install 中,dll 可以是 v3。 .Net 不会被您的配置绑定,因为它必须在那里找到 v2
  • 所以将 newVersion 设置为“1.0.0.0”
  • 但是文件FILE://c:/ABC-install/abc.dll可以更新到v3。更新后就不行了。
  • 你们知道代码库和程序集重定向之间的区别吗?我不明白。
猜你喜欢
  • 2015-02-18
  • 2011-04-28
  • 1970-01-01
  • 1970-01-01
  • 2012-06-23
  • 1970-01-01
  • 1970-01-01
  • 2014-09-01
  • 1970-01-01
相关资源
最近更新 更多