Configuration of .NET assembly binding of any newer assembly version in app.config <assemblyBinding>/<codeBase>

这一生的挚爱 提交于 2020-01-14 19:14:36

问题


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.

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>

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.

The question is: What should I put in the codeBase version?

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.

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.

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?

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


回答1:


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>


来源:https://stackoverflow.com/questions/27544918/configuration-of-net-assembly-binding-of-any-newer-assembly-version-in-app-conf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!