51

I'm installing NewtonSoft.Json for parsing Json in .NET application. When I'm using Visual Studio(VS) 2012, it can not be installed via NuGet. This is the error I have got:

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

I tried to copy the DLL over and just use it, seems like some dependencies screwed up in this version (10.0.2).

After few hours research, finally I've found out it is the problem of the compatibility of VS2012 and Newtonsoft Json 10.0.2.

RBT
  • 24,161
  • 21
  • 159
  • 240
Vin.X
  • 4,759
  • 3
  • 28
  • 35

7 Answers7

76

because NuGet Package Manager (Version 2.8.60318.667) for VS 2012 does not support .NETStandard (Used for Latest Newtonsoft Json Parser Lib. https://github.com/NuGet/Home/issues/3131

I resolve this issue by installing older version of Newtonsoft Json:

PM> Install-Package Newtonsoft.Json -Version 9.0.1

More details on: https://github.com/NuGet/Home/issues/5162 .

Neeraj Kumar
  • 771
  • 2
  • 16
  • 37
Vin.X
  • 4,759
  • 3
  • 28
  • 35
15

Installing/restoring NuGet packages which target .NET standard requires NuGet.exe version 3.4+.

From the release notes for v3.4: https://learn.microsoft.com/en-us/nuget/release-notes/nuget-3.4

New Features

  • Support for the netstandard and netstandardapp framework monikers

This version of NuGet comes with VS2015 Update 2

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

RBT
  • 24,161
  • 21
  • 159
  • 240
Kevin Secrist
  • 821
  • 10
  • 23
4

I had the same issue using VS2015 and creating a NuGet package with dependency on Newtonsoft.Json version=10.0.3. I used the approach suggested by Vin.X in his answer as the work around.

After installing Newtonsoft.Json version=9.0.1 into your project, add following description in your .nuspec file.

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

Application that consumes your package will install Newtonsoft.Json version=10.0.3 along with your package as a dependency into your project.

Grisha
  • 305
  • 1
  • 4
  • 12
3

Try removing existing version of package from solution package directory and then try the following command. It worked for me.

    PM> Install-Package Newtonsoft.Json -Version 9.0.1
Masood
  • 121
  • 4
  • 1
    I only needed to do the first step - remove a different (newer) version of the package from Solution->packages directory. Consider highlighting that part of your answer. – Ekus Nov 07 '19 at 20:04
1

I ran into the same issue. I think you need to update NuGet for VS2013 (*Prob VS2012 also)

here

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

Fiach Reid
  • 6,149
  • 2
  • 30
  • 34
0

This question isn't specifically about TFS/Azure Devops, but I ran into the exception in the title this morning, and my resolution gets around having to downgrade versions.

We updated Visual Studio on our build servers and all of our builds broke.

Below are the versions I'm currently targeting:

  • Nuget: 5.4.0
  • Newtonsoft.Json: 12.0.3
  • Azure Devops Server (on prem): 2019
  • Visual Studio 2019: 16.5.2

We found that we needed to add a task called NuGet Tool Installer in the beginning of our task list to force it to use version 5.4.0 because auto-discovery was selecting an older version and failing.

Nuget Tool Installer

Once this was functional, and packages restored, it failed to package our source for distribution. So we have the latest NuGet.exe, .NET Framework reference of NewtonSoft.Json (i.e. not netstandard), but still it wasn't working. We were using NuGet Packager previously, and I'm not entirely sure when the task became deprecated, but it was still functional for us until the VS updates. There is a new task called NuGet which has a drop down for the different features.

NuGet

Selecting Pack, and configuring the fields to mimic what the deprecated task had led to a successful build.

-1

Try to install Newtonsoft MsgPack it will install Newtonsoft.json DLL to your project.

RBT
  • 24,161
  • 21
  • 159
  • 240