传递依赖造成同一个DLL版本冲突冲突、版本、DLL

2023-09-03 10:34:32 作者:遗忘微笑

什么是.NET领域的最佳实践来管理,导致版本冲突的传递依赖?

在详细信息: 项目A依赖项目B这又依赖于库C

A计划还取决于项目X依赖于一个不同的库C的(潜在的)不兼容的版本。

A-> B-> Cv1.0 &功放; A-> X-> Cv2.0 其中, Cv1.0<> Cv2.0

有没有一种方法,使这项工作?

能不能做到不使用GAC?

即使B和X是二进制格式的唯一(来源无法访问)能不能做到?

在换句话说,有没有办法,我可以有计划B和X各自使用自己的依赖时,不会引起冲突中一起使用A计划。

注:我认识到,地理位置优越,我不应该在所有存在这个问题,但由于依赖于外部库扩展,这将是一个不可避免的副作用。所以,我想知道,如果它发生如何最好地处理它。

解决方案 maven传递依赖

有很多类似的问题在堆栈溢出。 对于如Referencing log4net的在同一溶液的2型动物版本

摘要:

确保您分别包含主要的可执行文件的文件夹中的部署文件夹1.0装配C和2.0。 更改app.config文件,其中包括类似以下内容:

 <结构>
   <运行>
    < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
      < dependentAssembly>
       < assemblyIdentity名称=C公钥=C的公钥标记/>
        < codeBase的版本=版本字符串C1.0如1.0.0.0的href =1.0 \ C.dll/>
        < codeBase的版本=版本字符串C2.0如2.0.0.0的href =2.0 \ C.dll/>
       < / assemblyIdentity>
      < / dependentAssembly>
    < / assemblyBinding>
   < /运行>
 < /结构>
 

您可以使用SN-T C.dll得到C的公钥标记

如果1.0版的C和2.0版有不同的公共密钥(虽然理想情况下,他们不应该),则包括两个dependentAssembly标签。

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.

解决方案

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

Summary:

Ensure that you deploy the assembly C in folders 1.0 and 2.0 respectively within the folder containing the main executable. 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.

 
精彩推荐
图片推荐