C# .net core - NuGet Package downgrade error

Posted on
software software engineering programming C# csharp

One of my clients has a large C# dotnet core codebase. It consists of many NuGet packages that in part depend on each other. Overall not an ideal position to be in.

When implementing a feature typically, multiple NuGet packages have to be touched, rebuilt, updated and tested. Sometimes this leads to conflicts and inconsistencies between NuGet Packages with specific Versions, or Bugs in general. One of the errors we sometimes hit is the “Package downgrade”-Error with the error number NU1605.

The error looks like this:

Detected package downgrade: 'PackageB' from 4.0.0 to 3.5.0. Reference the package directly from the project to select a different version.
  'PackageA' 3.5.0 -> 'PackageB' 3.5.0
  'PackageC' 4.0.0 -> 'PackageD' 4.0.0 -> 'PackageB' 4.0.0

The Error is described here in detail.

The easiest way to fix this is in our experience, to clear the NuGet-Caches and rebuild everything. Depending on the root cause there might be a better solution for your specific case. You can use the following dotnet core cli command to clear all local NuGet caches. Afterwards, the errors should be gone.

> dotnet nuget locals all -c