'Newtonsoft.Json' 已经为 'Microsoft.CSharp' 定义了依赖项

'Newtonsoft.Json' already has a dependency defined for 'Microsoft.CSharp'

我正在安装 NewtonSoft.Json 以在 .NET 应用程序中解析 Json。当我使用 Visual Studio(VS) 2012 时,无法通过 NuGet 安装它。 这是我遇到的错误:

'Newtonsoft.Json' already has a dependency defined for 'Microsoft.CSharp'

我试图复制 DLL 并使用它,似乎这个版本 (10.0.2) 中的某些依赖项搞砸了。

经过几个小时的研究,终于发现是VS2012和Newtonsoft的兼容性问题Json 10.0.2.

因为 VS 2012 的 NuGet 包管理器(版本 2.8.60318.667)不支持 .NETStandard(用于最新的 Newtonsoft Json 解析器库。 https://github.com/NuGet/Home/issues/3131

我通过安装旧版本的 Newtonsoft Json 解决了这个问题:

PM> Install-Package Newtonsoft.Json -Version 9.0.1

更多详情: https://github.com/NuGet/Home/issues/5162 .

我在使用 VS2015 和创建依赖于 Newtonsoft.Json version=10.0.3 的 NuGet 包时遇到了同样的问题。我在他的回答中使用了 Vin.X 建议的方法作为解决方法。

在您的项目中安装 Newtonsoft.Json version=9.0.1 后,在您的 .nuspec 文件中添加以下描述。

<dependencies>
      <dependency id="Newtonsoft.Json" version="10.0.3" />
</dependencies>

使用您的包的应用程序将安装 Newtonsoft.Json version=10.0.3 以及您的包作为项目的依赖项。

尝试安装 Newtonsoft MsgPack 它将安装 Newtonsoft.json DLL 到您的项目。

Installing/restoring 以 .NET 标准为目标的 NuGet 包需要 NuGet.exe 版本 3.4+。

来自 v3.4 的发行说明:https://docs.microsoft.com/en-us/nuget/release-notes/nuget-3.4

New Features

  • Support for the netstandard and netstandardapp framework monikers

此版本的 NuGet 附带 VS2015 更新 2

NuGet 3.4 was released March 30, 2016 as part of the Visual Studio 2015 Update 2 and Visual Studio 15 Preview Release

尝试从解决方案包目录中删除现有版本的包,然后 尝试以下命令。它对我有用。

    PM> Install-Package Newtonsoft.Json -Version 9.0.1

我运行遇到了同样的问题。我认为您需要为 VS2013 更新 NuGet(*Prob VS2012 也一样)

这里

https://marketplace.visualstudio.com/items?itemName=NuGetTeam.NuGetPackageManagerforVisualStudio2013

这个问题不是专门关于 TFS/Azure Devops,但我今天早上 运行 进入了标题中的异常,我的解决方案不得不降级版本。

我们在构建服务器上更新了 Visual Studio,但我们所有的构建都失败了。

以下是我目前定位的版本:

  • Nuget: 5.4.0
  • Newtonsoft.Json: 12.0.3
  • Azure Devops 服务器(本地):2019
  • Visual Studio 2019: 16.5.2

我们发现我们需要在任务列表的开头添加一个名为 NuGet Tool Installer 的任务以强制它使用版本 5.4.0,因为 auto-discovery 正在选择一个旧版本并且失败了。

一旦它起作用并恢复了包,它就无法打包我们的源代码以供分发。所以我们有最新的 NuGet.exe,NewtonSoft.Json 的 .NET Framework 参考(即不是 netstandard),但它仍然无法正常工作。我们以前使用 NuGet Packager,我不完全确定该任务何时被弃用,但在 VS 更新之前它仍然对我们有用。有一个名为 NuGet 的新任务,其中包含针对不同功能的下拉菜单。

选择 Pack,并配置字段以模仿已弃用的任务导致成功构建的内容。