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.

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.

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