Visual Studio 不断用旧版本覆盖 NewtonSoft.Json.DLL [英] Visual Studio keeps overwriting NewtonSoft.Json.DLL with an older version

查看:31
本文介绍了Visual Studio 不断用旧版本覆盖 NewtonSoft.Json.DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我构建包含引用的网站之外的任何其他项目时,Visual Studio 正在用旧版本覆盖我在项目引用和 NuGet 包文件中配置的正确版本的 NewtonSoft.Json.DLL.

好的.这是场景:

我有一个包含后端服务和网站的解决方案.该网站在 .NET 4.5 上运行,并配置了 NuGet 以引入 Newtonsoft.Json.DLL 的 6.0.1 版.

将dependenAssembly 绑定添加到web.config 文件中.

 <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"culture="neutral"/><bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/></dependentAssembly>

我可以毫无问题地构建和运行这个网站.

我最近将所有类库和后端服务从 .NET 4.0 更新到了 .NET 4.5.更新后,每当我构建类库之一或运行/调试后端服务时,该网站就无法运行.

无法加载文件或程序集Newtonsoft.Json"或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(来自 HRESULT 的异常:0x80131040)

我将此归结为以下事实:在重建类库之一或从 Visual Studio 运行/调试后端服务时,Newtonsoft.Json.DLL 被旧版本的文件覆盖 - 版本 4.5.11.由于显式的dependentAssembly 绑定,此后任何时候我访问网站时都会收到上面提到的无法加载..."错误.

如果我只想运行后端服务或网站中的一个或另一个,这没问题,但我必须同时运行它们才能使我的应用程序正常运行.但是由于这个错误,我无法在网站或网站崩溃的同时运行后端服务.

如何防止 Visual Studio 覆盖 DLL?

请注意,我在整个解决方案中只有 6.0.1 的参考集(即没有对 4.5.11 的参考任何地方).在网站中,我将 Newtonsoft.Json.DLL 的Copy Local"设置为 true,Specific Version"也设置为 true.

解决方案

这是一个已知错误 Windows Azure VS 工具

解决方法:

  • 从 Program FilesMicrosoft 中删除 Newtonsoft.Json.dll 文件SDKsWindows Azure.NET SDKv2.3 ef 文件夹.

  • 卸载 Windows Azure VS Tools v 2.3

Visual Studio is overwriting the correct version of NewtonSoft.Json.DLL that I have configured in both my project references and the NuGet package file with an older version when I build any other project besides the website that contains the reference.

OK. Here is the scenario:

I have a solution with a backend service and a website. The website is running on .NET 4.5 and is configured with NuGet to pull in version 6.0.1 of Newtonsoft.Json.DLL.

<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />

Which adds the dependenAssembly binding to the web.config file.

  <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>

I can build and run this website without any problems.

I recently updated all of the class libraries and backend service from .NET 4.0 to .NET 4.5. After the update, whenever I build one of the class libraries or run/debug the backend service, the website becomes inoperable.

Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

I tracked this down to the fact that when rebuilding one of the class libraries or running/debugging the backend service from Visual Studio, the Newtonsoft.Json.DLL gets overwritten with an older version of the file - version 4.5.11. Because of the explicit dependentAssembly binding, any time I access the website after that I get the 'Could not load ...' error mentioned above.

This would be OK if I just wanted to run one or the other of the backend service or the website, but I have to run them both together to get my application running properly. But because of this error I cannot have the backend service running at the same time as the website or the website crashes.

How do I prevent Visual Studio from overwriting the DLL?

Note that I have the reference set for only 6.0.1 across the entire solution (i.e. there is no reference anywhere to 4.5.11). And in the website I have 'Copy Local' set to true and 'Specific Version' is also set to true for the Newtonsoft.Json.DLL.

解决方案

This is a known bug in Windows Azure VS Tools

Workarounds:

  • Remove Newtonsoft.Json.dll file from Program FilesMicrosoft SDKsWindows Azure.NET SDKv2.3 ef folder.

  • Uninstall Windows Azure VS Tools v 2.3

这篇关于Visual Studio 不断用旧版本覆盖 NewtonSoft.Json.DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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