No Way to Resolve Conflict Between dlls

≡放荡痞女 提交于 2020-04-08 10:18:11

问题


I'm getting a wall of warnings similar to the following in my build:

No way to resolve conflict between "Newtonsoft.Json, Version=7.0.0.0" 
and "Newtonsoft.Json, Version=6.0.0.0". 
Choosing "Newtonsoft.Json, Version=7.0.0.0" arbitrarily.

I get additional warnings for the following dlls (repeats are intentional):

Microsoft.Owin
System.Web.Http
Newtonsoft.Json
System.Net.Http.Formatting
Microsoft.Owin
Microsoft.ApplicationInsights

As well as a matching message for each warning:

Consider app.config remapping of assembly to solve conflict and get rid of warning.

Finally, I get this conflict:

Microsoft.Common.CurrentVersion.targets Found conflicts between 
different versions of the same dependent assembly. 
Please set the "AutoGenerateBindingRedirects" property to true 
in the project file.

I've read every stack overflow and MSDN answer I could find for these messages. According to this answer, the best solution is to change the references that are causing the conflicted warnings to reference the same version. What seems to be the problem is that the chain of assemblies coming from some of the 53 projects in the solution depend on different assemblies with different versions. I am unable to tell which projects cause these warnings, and the binding redirects (auto-generated in every single project, I checked) have no effect on the warnings.

What can I do to resolve these build warnings?


回答1:


They are all the same warning and are actually telling you what to do. You can either clean up all the references in the project. If you are using NuGet, this shouldn't be too much of an issue. Go into Manage NuGet Packages. you should see duplicate packages in you list. Move the references to the older package to new version of the package. This is one way to resolve the conflicts.

The second way would be to add binding redirects for all the assemblies that are conflicted. Here's an example of a Json.net redirect.

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>


来源:https://stackoverflow.com/questions/37998452/no-way-to-resolve-conflict-between-dlls

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