处理相同依赖项的不同版本

时间:2020-01-16 12:23:13

标签: c# .net-core

因此,我刚刚安装了Entity Framework Profiler,当我启动Web应用程序并提出了第一个请求时,Hangfire突然找不到System.Data.SqlClient。 事实证明,Entity Framework Profiler所需的System.Data.SqlClient为4.2.0.2,而Hangfire所需的版本为4.2.0.0。 因此,现在我必须拥有我无法控制的不同库,具体取决于同一个库,但有2个不同的版本。

我得到了错误:

       (ResolveAssemblyReferences target) -> 
     C:\Program Files\dotnet\sdk\3.1.100\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Data.SqlClient" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed.

因此,我查看了构建日志,发现除了上面的错误所说明的内容之外,几乎没有更多的信息,除了哪些库具有该依赖性。

浏览日志,它确实指出找不到4.2.0.2文件,但后来我遇到了冲突:

         Dependency "System.Data.SqlClient, Version=4.2.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
         Could not resolve this reference. Could not locate the assembly "System.Data.SqlClient, Version=4.2.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
         Required by "HibernatingRhinos.Profiler.Appender".

冲突:

         There was a conflict between "System.Data.SqlClient, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Data.SqlClient, Version=4.2.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
         "System.Data.SqlClient, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Data.SqlClient, Version=4.2.0.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.

有办法解决吗?

2 个答案:

答案 0 :(得分:0)

查看添加此绑定重定向是否有帮助。我假设您正在.net框架上运行。

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Data.SqlClient" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="4.2.0.0-4.2.0.2" newVersion="4.2.0.2" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

答案 1 :(得分:0)

所以我的问题是,我手动添加了一个库作为参考,当我通过NuGet添加它时,问题就消失了。 看来NuGet可以更好地处理这些引用。