Transitive Dependency causing Conflicting version of same DLL

拟墨画扇 提交于 2019-12-31 13:47:10

问题


What is the best practice in the .NET world to manage transitive dependencies that cause version conflict ?

In details : Project A Depends on Project B which in turn depends on library C

also

Project A also depends on Project X which depends on a DIFFERENT and (potentially) incompatible version of library C.

A->B->Cv1.0
&
A->X->Cv2.0
where
Cv1.0 <> Cv2.0

  • Is there a way to make this work ?

  • Can it be done WITHOUT using the GAC ?

  • Can it be done even if B and X are in binary format only (source not accessible) ?

In other words is there a way where I can have Project B and X each using their own dependencies when used together in Project A without causing conflicts.

NOTE: I realize that ideally I should not have this problem at all but as reliance on external libraries expands this will be an unavoidable side effect. So I am wondering should it occur how best to deal with it.


回答1:


There are a lot of similar questions On Stack Overflow. For e.g. Referencing 2 different versions of log4net in the same solution

Summary:

  1. Ensure that you deploy the assembly C in folders 1.0 and 2.0 respectively within the folder containing the main executable.
  2. Change app.config file and include something like following:
 <configuration>
   <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
       <assemblyIdentity name="C" publicKeyToken="C's public key token" />
        <codeBase version="version string for C1.0 e.g. 1.0.0.0" href="1.0\C.dll" />
        <codeBase version="version string for C2.0 e.g. 2.0.0.0" href="2.0\C.dll" />
       </assemblyIdentity>
      </dependentAssembly>
    </assemblyBinding>
   </runtime>
 </configuration>

you can get the public key token of C using sn -T C.dll

If v1.0 and v2.0 of C have different public key (though ideally they shouldn't) then include two dependentAssembly tags.



来源:https://stackoverflow.com/questions/11335577/transitive-dependency-causing-conflicting-version-of-same-dll

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