VS2013新建MVC5项目,使用nuget更新项目引用后发生Newtonsoft.Json引用冲突的解决办法

错误信息如下:

错误    3    类型“Newtonsoft.Json.JsonPropertyAttribute”同时存在于“c:Program Files (x86)Microsoft Visual Studio 12.0BlendNewtonsoft.Json.dll”和“d:projectpackagesNewtonsoft.Json.6.0.1lib et45Newtonsoft.Json.dll”中    D:projectp1HubsTestHub.cs    35    10    p1

警告    1    无法解决“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”与“Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”之间的冲突。正在随意选择“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”。    p1

警告    2    发现同一依赖程序集的不同版本间存在冲突。在 Visual Studio 中,请双击此警告(或选择此警告并按 Enter)以修复冲突;否则,请将以下绑定重定向添加到应用程序配置文件中的“runtime”节点: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" /><bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /></dependentAssembly></assemblyBinding>    p1

image

这也许是json.net更新脚本的问题吧,也许以后就不会再出现这种错误了。

解决方法:

用记事本打开项目文件(*.csproj)

可以找到在这个文件中,有两处Newtonsoft.Json的引用,删掉老版本的引用就好了。

image

(上图为更新后的引用,6.0.1版,此处保留)

image

(上图为老版组件引用,冲突就是它引发的,截图内容全部删除)

更多参考:http://stackoverflow.com/questions/21498074/how-can-i-fix-assembly-version-conflicts-with-json-net-after-updating-nuget-pack

原文地址:https://www.cnblogs.com/xwgli/p/3617645.html