传递依赖造成同一个DLL版本冲突 [英] Transitive Dependency causing Conflicting version of same DLL

查看:145
本文介绍了传递依赖造成同一个DLL版本冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是.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计划。

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

解决方案

有很多类似的问题在堆栈溢出。 对于如<一href="http://stackoverflow.com/questions/3158928/referencing-2-differents-versions-of-log4net-in-the-same-solution">Referencing log4net的在同一溶液的2型动物版本

摘要:

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

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

您可以使用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:

  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.

这篇关于传递依赖造成同一个DLL版本冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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