0

I have a project implemented using .NET 4.6.1. I build this project using TFS. One of the build tasks is to create a nuget package from this project as it contains shared code used by other projects. I recently needed to upgrade the version of Newtonsoft.Json from v9.0.1 to v12.0.1 (I've added some new functionality which forced me to upgrade my version of Newtonsoft.Json).

I'm now getting the error 'Newtonsoft.Json' already has a dependency defined for 'Microsoft.CSharp' from my build task which creates the nuget package.

Here's the build command which creates the nuget package.

NuGet.exe pack "Common.csproj" -OutputDirectory "\packages\Common" -Properties Configuration=Release -version 1.2.3.4

Here's the packages.config file.

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.IdentityModel.Logging" version="1.1.2" targetFramework="net461" />
  <package id="Microsoft.IdentityModel.Tokens" version="5.1.2" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="12.0.1" targetFramework="net461"  />
  <package id="Sendgrid" version="9.9.0" targetFramework="net452" />
  <package id="System.IdentityModel.Tokens.Jwt" version="5.1.2" targetFramework="net461" />
  <package id="System.Net.Http" version="4.0.0" targetFramework="net452" />
  <package id="Twilio" version="5.23.0" targetFramework="net461" />
</packages>

I've had a look at this question but none of those answers are applicable.

Our build server is using nuget version 3.2.1.10581

DomBurf
  • 2,452
  • 5
  • 36
  • 71
  • That error message usually means the NuGet version is too old and does not understand the dependencies which are target framework specific. I would try using a more recent NuGet version. 3.2.1 is quite old. – Matt Ward Dec 15 '18 at 11:10
  • I'll try upgrading nuget.exe and see what happens. Thanks. – DomBurf Dec 16 '18 at 09:06
  • @MattWard That worked for me. If you want to submt this as a solution I'll mark it as the answer. Cheers. – DomBurf Dec 17 '18 at 08:53

1 Answers1

0

For anyone else running into this issue:

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

We updated Visual Studio on the build servers which broke Nuget restores. 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. 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.