在 app.config <assemblyBinding>/<codeBase> 中配置任何较新的程序集版本的 .NET 程序集绑定 [英] Configuration of .NET assembly binding of any newer assembly version in app.config &lt;assemblyBinding&gt;/&lt;codeBase&gt;

查看:26
本文介绍了在 app.config <assemblyBinding>/<codeBase> 中配置任何较新的程序集版本的 .NET 程序集绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In a C# project, I use an external assembly and add it in the References of the project. Let's say the assembly is called "ABC" , located at compile-time c:complie-timeabc.dll of version 1.0.0.0. The "Copy Local" is set to false.

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

Because it is not copied local, the assembly location has to be specified in 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-installabc.dll.

The ABC assembly is provided by the ABC application installation. So at run-time, the dll is in different location c:ABC-installabc.dll.

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

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

If the user install a newer version of ABC says 1.1.0.0, and it is known to be backward compatible, the above will not work because the .NET framework is looking for version 1.0.0.0 at c:ABC-installabc.dll if i put 1.0.0.0 there.

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

The condition is the at compile time we don't know what will be the version number in c:ABC-install. All we know is it is backward compatible. The project should be able to run with all version of ABC assembly.

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

How to configure the app.config to allow newer version of an external assembly to be bound but runtime version is unknown at compile-time, while at complie-time the project was built based on the 1.0.0.0 dll in the reference setting?

codeBase 版本为 ????清楚地表明问题.

codeBase version to ???? to show clearly the question.

推荐答案

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

sample fragment taken from a standard (I believe visual studio generated web.config ), use the bindingRedirect part.

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

这篇关于在 app.config <assemblyBinding>/<codeBase> 中配置任何较新的程序集版本的 .NET 程序集绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆