I created a new ASP.NET MVC 5 web project in VS 2013 (Update 1) then updated all NuGet packages. When I build the project, I get the following warning:
我创建了一个新的ASP。NET MVC 5 web project在VS 2013(更新1)中更新了所有NuGet包。当我构建这个项目时,我得到以下警告:
warning MSB3243: No way to resolve conflict between "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed".
警告MSB3243:没有办法解决“Newtonsoft”之间的冲突。Json,版本=6.0.0.0,Culture=中性,PublicKeyToken=30ad4fe6b2a6aeed和Newtonsoft。Json、Version = 4.5.0.0文化=中立,都30 ad4fe6b2a6aeed”。
When I check the web.config, however, I see that a binding redirect is in place:
当我上网的时候。但是配置,我看到绑定重定向已经就绪:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
Which is exactly what the warning advises.
这正是警告所建议的。
How can I fix this warning?
我如何修正这个警告?
8 个解决方案
#1
84
Here the steps I used to fix the warning:
这里是我用来修正警告的步骤:
- Unload project in VS
- 在VS卸载项目
- Edit .csproj file
- 编辑.csproj文件
- Search for all references to Newtonsoft.Json assembly
- Found two, one to v6 and one to v5
- 找到两个,一个到v6,一个到v5
- Replace the reference to v5 with v6
- 将对v5的引用替换为v6
- 搜索所有对Newtonsoft的引用。Json程序集找到了两个,一个到v6,一个到v5,用v6替换对v5的引用
- Reload project
- 重新加载项目
- Build and notice assembly reference failure
- 构建并注意程序集引用失败
- View References and see that there are now two to Newtonsoft.Json. Remove the one that's failing to resolve.
- 查看引用,现在有两个to Newtonsoft.Json。删除无法解决的那个。
- Rebuild - no warnings
- 重建——没有警告
#2
26
I had this problem because I updated packages, which included Microsoft.AspNet.WebApi that has a reference to Newtonsoft.Json 4.5.6 and I already had version 6 installed. It wasn't clever enough to use the version 6.
我遇到这个问题是因为我更新了包,其中包括Microsoft.AspNet。对Newtonsoft有引用的WebApi。我已经安装了版本6。使用版本6还不够聪明。
To resolve it, after the WebApi update I opened the Tools > NuGet Package Manager > Pacakge Manager Console and ran:
为了解决这个问题,在WebApi更新之后,我打开了工具> NuGet包管理器> Pacakge Manager控制台并运行:
Update-Package Newtonsoft.Json
The log showed that the 6.0.x and 4.5.6 versions were all updated to the latest one and everything was fine.
log表示0。x和4.5.6版本都更新到最新版本,一切正常。
I have a feeling this will come up again.
我有一种感觉这将再次发生。
#3
12
I found to delete this section from the project file fix the problem.
我发现从项目文件中删除这一节可以修复问题。
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
#4
8
If none of the above works, try using this in web.config or app.config:
如果以上方法都不奏效,请尝试在web中使用它。配置或app.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
#5
4
The final solution to your assembly redirect errors
Okay, hopefully this should help resolve any (sane) assembly reference discrepancies ...
好的,希望这能帮助解决任何(理智的)程序集引用差异……
- Check the error.
- 检查错误。
- Check web.config after the assembly redirect. Create one if not exists.
- 检查网络。在程序集重定向之后配置。创建一个如果不存在。
- Right-click the reference for the assembly and choose Properties.
- 右键单击程序集的引用并选择Properties。
- Check the Version (not Runtime version) in the Properties table. Copy that.
- 检查属性表中的版本(不是运行时版本)。复制。
- Paste into the newVersion attribute.
- 粘贴到newVersion属性。
- For convenience, change the last part of the oldVersion to something high, round and imaginary.
- 为了方便起见,将旧版本的最后一部分更改为高、圆和虚构的内容。
Rejoice.
喜乐。
#6
2
Remember that with the binding redirection
记住绑定重定向
oldVersion="0.0.0.0-6.0.0.0"
oldVersion = " 0.0.0.0-6.0.0.0 "
You are saying that the old versions of the dll are between version 0.0.0.0 and version 6.0.0.0.
您说的是dll的旧版本在版本0.0.0.0.0.0和版本6.0.0.0.0之间。
#7
0
I had similar issue and just wanted to post an answer for others in my situation.
我也有类似的问题,只是想在我的情况下给别人一个答案。
I have a solution running a ASP.NET Web Application with multiple other C# class lib projects.
我有一个运行ASP的解决方案。NET Web应用程序与多个其他c#类库项目。
My ASP.NET Web Application wasn't using json, but other projects where.
我的ASP。NET Web应用程序没有使用json,而是使用了其他项目。
This is how I fixed it:
我就是这样修正的:
- I made sure all projects where using latest version (6) using NuGet Update on all projects currently using any version of json - this didn't fix the issue
- 我确保所有使用最新版本(6)使用NuGet更新的项目都使用任何版本的json——这并没有解决问题
- I added json to the web application using NuGet - this fixed the issue (let me dive into why):
- 我使用NuGet向web应用程序添加了json——这解决了问题(让我来深入研究为什么):
Step 2 was first of all adding a configuration information for json, that suggest that all projects, use the latest version (6) no matter what version they have. Adding the assembly binding to Web.Config is most likely the fix.
第2步首先为json添加了一个配置信息,该信息建议所有项目都使用最新的版本(6),不管它们有什么版本。将程序集绑定添加到Web。配置是最可能的修复。
However, step 2 also cleaned up som legacy code. It turned out we have previously used an old version (5) of json in our Web Application and the NuGet folders wasn't deleted when the reference was (I suspect: manually) removed. Adding the latest json (6), removed the old folders (json v5). This might be part of the fix as well.
然而,第2步也清理了som遗留代码。事实证明,我们以前在Web应用程序中使用过json的旧版本(5),并且在删除引用(我怀疑是手动删除的)时,NuGet文件夹没有被删除。添加最新的json(6),删除旧文件夹(json v5)。这也可能是修复的一部分。
#8
0
I updated my package and even reinstalled it - but I was still getting the exact same error as the OP mentioned. I manually edited the referenced dll by doing the following.
我更新了我的包,甚至重新安装了它——但是我仍然得到与OP提到的完全相同的错误。我通过以下操作手动编辑所引用的dll。
I removed the newtonsoft.json.dll from my reference, then manually deleted the .dll from the bin directoy. Then i manually copied the newtonsoft.json.dll from the nuget package folder into the project bin, then added the reference by browsing to the .dll file.
我删除了newtonsoft.json。从我的引用dll中,然后从bin directoy手动删除。dll。然后我手动复制了newtonsoft.json。从nuget包文件夹的dll到项目bin,然后通过浏览.dll文件添加引用。
Now my project builds again.
现在我的项目再次构建。
#1
84
Here the steps I used to fix the warning:
这里是我用来修正警告的步骤:
- Unload project in VS
- 在VS卸载项目
- Edit .csproj file
- 编辑.csproj文件
- Search for all references to Newtonsoft.Json assembly
- Found two, one to v6 and one to v5
- 找到两个,一个到v6,一个到v5
- Replace the reference to v5 with v6
- 将对v5的引用替换为v6
- 搜索所有对Newtonsoft的引用。Json程序集找到了两个,一个到v6,一个到v5,用v6替换对v5的引用
- Reload project
- 重新加载项目
- Build and notice assembly reference failure
- 构建并注意程序集引用失败
- View References and see that there are now two to Newtonsoft.Json. Remove the one that's failing to resolve.
- 查看引用,现在有两个to Newtonsoft.Json。删除无法解决的那个。
- Rebuild - no warnings
- 重建——没有警告
#2
26
I had this problem because I updated packages, which included Microsoft.AspNet.WebApi that has a reference to Newtonsoft.Json 4.5.6 and I already had version 6 installed. It wasn't clever enough to use the version 6.
我遇到这个问题是因为我更新了包,其中包括Microsoft.AspNet。对Newtonsoft有引用的WebApi。我已经安装了版本6。使用版本6还不够聪明。
To resolve it, after the WebApi update I opened the Tools > NuGet Package Manager > Pacakge Manager Console and ran:
为了解决这个问题,在WebApi更新之后,我打开了工具> NuGet包管理器> Pacakge Manager控制台并运行:
Update-Package Newtonsoft.Json
The log showed that the 6.0.x and 4.5.6 versions were all updated to the latest one and everything was fine.
log表示0。x和4.5.6版本都更新到最新版本,一切正常。
I have a feeling this will come up again.
我有一种感觉这将再次发生。
#3
12
I found to delete this section from the project file fix the problem.
我发现从项目文件中删除这一节可以修复问题。
<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.6.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
#4
8
If none of the above works, try using this in web.config or app.config:
如果以上方法都不奏效,请尝试在web中使用它。配置或app.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
#5
4
The final solution to your assembly redirect errors
Okay, hopefully this should help resolve any (sane) assembly reference discrepancies ...
好的,希望这能帮助解决任何(理智的)程序集引用差异……
- Check the error.
- 检查错误。
- Check web.config after the assembly redirect. Create one if not exists.
- 检查网络。在程序集重定向之后配置。创建一个如果不存在。
- Right-click the reference for the assembly and choose Properties.
- 右键单击程序集的引用并选择Properties。
- Check the Version (not Runtime version) in the Properties table. Copy that.
- 检查属性表中的版本(不是运行时版本)。复制。
- Paste into the newVersion attribute.
- 粘贴到newVersion属性。
- For convenience, change the last part of the oldVersion to something high, round and imaginary.
- 为了方便起见,将旧版本的最后一部分更改为高、圆和虚构的内容。
Rejoice.
喜乐。
#6
2
Remember that with the binding redirection
记住绑定重定向
oldVersion="0.0.0.0-6.0.0.0"
oldVersion = " 0.0.0.0-6.0.0.0 "
You are saying that the old versions of the dll are between version 0.0.0.0 and version 6.0.0.0.
您说的是dll的旧版本在版本0.0.0.0.0.0和版本6.0.0.0.0之间。
#7
0
I had similar issue and just wanted to post an answer for others in my situation.
我也有类似的问题,只是想在我的情况下给别人一个答案。
I have a solution running a ASP.NET Web Application with multiple other C# class lib projects.
我有一个运行ASP的解决方案。NET Web应用程序与多个其他c#类库项目。
My ASP.NET Web Application wasn't using json, but other projects where.
我的ASP。NET Web应用程序没有使用json,而是使用了其他项目。
This is how I fixed it:
我就是这样修正的:
- I made sure all projects where using latest version (6) using NuGet Update on all projects currently using any version of json - this didn't fix the issue
- 我确保所有使用最新版本(6)使用NuGet更新的项目都使用任何版本的json——这并没有解决问题
- I added json to the web application using NuGet - this fixed the issue (let me dive into why):
- 我使用NuGet向web应用程序添加了json——这解决了问题(让我来深入研究为什么):
Step 2 was first of all adding a configuration information for json, that suggest that all projects, use the latest version (6) no matter what version they have. Adding the assembly binding to Web.Config is most likely the fix.
第2步首先为json添加了一个配置信息,该信息建议所有项目都使用最新的版本(6),不管它们有什么版本。将程序集绑定添加到Web。配置是最可能的修复。
However, step 2 also cleaned up som legacy code. It turned out we have previously used an old version (5) of json in our Web Application and the NuGet folders wasn't deleted when the reference was (I suspect: manually) removed. Adding the latest json (6), removed the old folders (json v5). This might be part of the fix as well.
然而,第2步也清理了som遗留代码。事实证明,我们以前在Web应用程序中使用过json的旧版本(5),并且在删除引用(我怀疑是手动删除的)时,NuGet文件夹没有被删除。添加最新的json(6),删除旧文件夹(json v5)。这也可能是修复的一部分。
#8
0
I updated my package and even reinstalled it - but I was still getting the exact same error as the OP mentioned. I manually edited the referenced dll by doing the following.
我更新了我的包,甚至重新安装了它——但是我仍然得到与OP提到的完全相同的错误。我通过以下操作手动编辑所引用的dll。
I removed the newtonsoft.json.dll from my reference, then manually deleted the .dll from the bin directoy. Then i manually copied the newtonsoft.json.dll from the nuget package folder into the project bin, then added the reference by browsing to the .dll file.
我删除了newtonsoft.json。从我的引用dll中,然后从bin directoy手动删除。dll。然后我手动复制了newtonsoft.json。从nuget包文件夹的dll到项目bin,然后通过浏览.dll文件添加引用。
Now my project builds again.
现在我的项目再次构建。