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

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

问题描述

在C#项目中,我使用外部程序集并将其添加到项目的引用中。假设程序集名为 ABC ,位于版本 1.0.0.0 <的编译时 c:\complie-time\abc.dll / strong>。

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-time\abc.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-install\abc.dll

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

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

如果用户安装较新版本的ABC,则说 1.1.0.0 ,并且已知它是向后兼容的,因此上述操作将不起作用,因为.NET框架正在 c:\ABC-install\abc寻找 1.0.0.0 版本.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-install\abc.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)中提取的示例片段

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&lt; assemblyBinding&gt; /&lt; codeBase&gt;中配置任何新的程序集版本的.NET程序集绑定。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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