Downgrade (use a lower-versioned library) with a binding redirect

北战南征 提交于 2020-01-02 05:01:09

问题


I'm using an older version of NHibernate (v3.0.0.1001) and I'm stuck to it because the new LINQ provider breaks quite a few of my queries (something I'll be trying to fix later). I want to update a library that uses NHibernate v3.1.0.4000.

I've tried adding a binding redirect in the App.config:

<?xml version="1.0"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral"/>
                <bindingRedirect oldVersion="0.0.0.0-3.1.0.4000" newVersion="3.0.0.1001"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

But when I compile, I get:

error CS1705: Assembly 'My3rdPartyDll, Version=0.5.0.170, Culture=neutral, PublicKeyToken=null' uses 'NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' which has a higher version than referenced assembly 'NHibernate, Version=3.0.0.1001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4'

Is it possible to use a binding redirect to point to a downgrade?


回答1:


You can use the probing Element to specify a specific folder to find the dll, and then you can just past the dll into that folder.

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <probing privatePath="Assemblies"/> 
    </assemblyBinding>
</runtime>

You can aslo specify a specific assembly to use which is what I think you are looking for.

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WorkflowLibrary1" publicKeyToken="8afb6d596a769080" />
        <codeBase version="1.0.0.0" href="Version_1_0_0_0/WorkflowLibrary1.dll"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

This Link goes into more details about this.



来源:https://stackoverflow.com/questions/6626874/downgrade-use-a-lower-versioned-library-with-a-binding-redirect

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