119

I have just updated all my nuget packages for my solution (dotnet core 1.1 project).

I am now getting the following warnings and I don't really know what they mean.

NETStandard.Library downgrade warning


Update: I am still getting warnings mentioned above. My web projects warn about the Microsoft.NETCore.App package (see screenshot below) and my lib projects warn about NETStandard.Library (see screenshot above)

Microsoft.NETCore.App downgrade warning

When trying to update Microsoft.NETCore.App in the NuGet package manager, I am getting the following error:

NuGet upgrade error

Hope someone can help me get rid of those warnings and setup everything it is meant to be, so I can update all my packages.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Nik
  • 2,863
  • 6
  • 24
  • 29

22 Answers22

69

This situation occurred to me after opening an existing solution but instead of Warnings, they were Errors.

I opened the YourAwesomeApp.csproj file and went through the "Detected package downgrade" errors one-by-one and manually changed the version of that line item from the existing version to the specified version that was shown in the error itself.

For example, if the Error says downgrade detected "SqlServer 1.0.4 -> 1.0.3" then find the line for package SqlServer and edit the version from 1.0.3 to 1.0.4.

Those errors should disappear after building the project.

The downside to this that I only had 5 errors this time but what if another person's project contained say 50 such errors. Then that person's task of manually editing those lines would be very tedious and time-consuming.

Jimmy Shaw
  • 1,097
  • 1
  • 12
  • 19
  • 7
    This works for me when afterwards I did a `dotnet restore` on the failing to build project. – Aage Feb 14 '19 at 07:17
  • 4
    Worked for me but had to do a "Clean Solution" and then build. – Neville Oct 31 '19 at 09:50
  • 1
    Detected package downgrade: Microsoft.Extensions.Logging from 3.1.3 to 2.2.0. Reference the package directly from the project to select a different version. When I searched for Microsoft.Extensions.Logging I did not find any. – Gopi Apr 23 '20 at 12:38
62

This generally happens because the item you are attempting to install requires a more recent version of a sub-dependency than you have already included in your project.

The solution is to update or delete the existing dependency that is in your project prior to installing the package.

Example:

Detected package downgrade: Newtonsoft.Json from 9.0.0 to 8.0.0.

This means you have Newtonsoft.Json 8.0.0 already listed as a dependency in your project, but the package you are trying to install requires at least version 9.0.0 as a dependency.

This is because Visual studio won't automatically upgrade this dependency as you've specified an explicit version for your project. You can either upgrade the dependency in your project to the minimum required version or remove it from your project, and let the package you're installing handle it.

To resolve this, in our example above, this would mean finding 'Newtonsoft.Json 8.0.0' and upgrading it to version '9.0.0' or simply removing it from your project prior to installing your package.

27

As per answer above the working solution is to remove the following line from your csproj file.

Web App project:

<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>

Lib project:

<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
johnnyRose
  • 7,310
  • 17
  • 40
  • 61
Nik
  • 2,863
  • 6
  • 24
  • 29
20

In my case neither of those properties were set in my csproj files.

I had to tell VS to update those packages via NuGet.

The warnings appeared for me after resolving the warning for explicit reference to implicit dependency .NETCore.App after moving from 1.0 to 1.1.

UPDATE 21/09/17

This also seems to affect upgrades to 2.0, the resolution is the same. Update those packages manually with NuGet. Thanks to IbrarMumtaz for pointing this out!

Gerard Wilkinson
  • 1,512
  • 14
  • 33
  • This is happening to me now from 1.1 > 2.0. : ? – IbrarMumtaz Sep 18 '17 at 15:31
  • It is almost definitely best to explicitly set your package versions rather than ignore the warning or try some other more generic solution. If you want to avoid the downgrades, be explicit about it. This is the best answer. – Dan Field Apr 23 '18 at 18:44
  • 8
    Unless nuget won't let you! Nightmare. – Oliver May 22 '18 at 16:18
19

I was able to fix some error like that adding NoWarn in cproj

<Project Sdk="Microsoft.NET.Sdk">

 <PropertyGroup>
    <NoWarn>$(NoWarn);NU1605</NoWarn>
  </PropertyGroup>

...
</Project>

You may want to add it only temporarily during multiple package upgrade and remove it later.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170
mrapi
  • 5,831
  • 8
  • 37
  • 57
  • 4
    The only problem is that "temporarily" inevitably becomes permanently. Either whoever makes the change forgets to change it back or doesn't document it and maintenance gets passed to someone else who never knew about the temporary fix in the first place. Or they never have time to deal with it and it eventually fades into the mists of time, unchanged. – Simon Elms Sep 24 '21 at 04:39
12

I was able to get rid of these warnings in my project by removing the <NetStandardImplicitPackageVersion> element from the csproj file.

There's some information in this article about implicit metapackages, which seems to be the root cause of this problem.

You might also need to update some dependencies. For example, I had to upgrade BenchmarkDotNet from 0.10.1 to 0.10.3 to get rid of a few warnings like the ones you're seeing.

Drew Noakes
  • 300,895
  • 165
  • 679
  • 742
8

Try removing:

<IsPackable>false</IsPackable>

from your project file - this is what worked for me!

If you are still left with NU1605 Error code you can ignore it by adding the following to your project file:

<PropertyGroup>
    <NoWarn>NU1605</NoWarn>
</PropertyGroup>
Emil
  • 2,196
  • 2
  • 25
  • 24
5

Try using NuGet

I was getting:

error NU1605: Detected package downgrade: System.Net.NameResolution from 4.3.0 to 4.0.0. Reference the packagedirectly from the project to select a different version.

So I referenced the package directory by running (in the project folder):

dotnet add package System.Net.NameResolution

See NuGet Errors - NU1605

Issue:

A dependency package specified a version constraint on a higher version of a package than restore ultimately resolved. That is, because of the "nearest wins" rule when resolving packages, a nearer package in the graph may have overridden a distant package.

Solution:

Add a direct reference to the project for the higher version of the package that you want to use.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Robert Brooker
  • 2,148
  • 24
  • 22
5
  1. Identify the package detected. For example in my case, it is System.Diagonistics.DiagonsticSource enter image description here

  2. Find the location of this assembly reference from your project (Reference > Properties > Path) enter image description here

  3. Copy path and check. In my case, the project is referencing 4.6.0 but the assembly that I was about to install requires version 5.0.0 of System.Diagonistics.DiagonsticSource as minimum

enter image description here

  1. Go to Manage NuGet Packages for the project and search for "System.Diagonistics.DiagonsticSource" and update. Bear in mind that this may also cause another "Detected package downgrade" error (you should go back to step one if this happens)
    enter image description here

  2. Now, install the assembly you initially wanted to install (In my case it was Microsoft.ApplicationInsights)

user890255
  • 458
  • 5
  • 9
3

In my case, this error was not related to .NET Core but to .NET Standard.

I had two libraries A, and B. Library A depended on some nuget package X, and library B depended on A. Once I upgraded X to a new version, somehow it started depending on a new version of NETStandard.Library nuget package (from 2.0.2 to 2.0.3), which broke the build of B with the error Detected package downgrade: NETStandard.Library from 2.0.3 to 2.0.2. Reference the package directly from the project to select a different version.

Once I added the NETStandard.Library nuget package as a dependency to B (obviously targetting the latest version 2.0.3), the error went away, even if a new warning appeared:

/usr/local/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.targets(5,5): Warning NETSDK1023: A PackageReference for 'NETStandard.Library' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs (NETSDK1023) (GWallet.Frontend.XF)

knocte
  • 16,941
  • 11
  • 79
  • 125
  • i updated project "B" as you explained, not worked for me. but thanks. this gives me some understanding to find other solution – Pajri Aprilio Dec 20 '18 at 13:01
  • please post your solution as a new answer – knocte Dec 20 '18 at 13:08
  • still not found yet. but i'm trying to remove dependency between A and B first, then make A and B dependent to the same version of X then add dependency between A and B again – Pajri Aprilio Dec 20 '18 at 13:15
2

Manually removing the nuget packages dependencies from the project and Install-Package for each of them fixed the problem in my case.

Max Favilli
  • 6,161
  • 3
  • 42
  • 62
2

The issue for me was that I had packages installed locally that were of higher versions than my projects referenced. If you go to Tools > NuGet Package Manager > Package Manager Settings > General > Clear All NuGet Cache(s) then rebuild your solution it'll install the packages referenced and the errors will go.

Dystar
  • 97
  • 8
1

I was trying to upgrade Microsoft.AspNetcore.MVC to Version 2+. The solution for me was to upgrade all of the other dependencies first to 2+, then finally upgrade .MVC.

Eric
  • 7,930
  • 17
  • 96
  • 128
1

I could solve the problem by downloading earlier version of the package causing the problem, that seems to be caused by depending on a .NET Standard version that's not installed, this also should be solved by updating Visual Studio.

mshwf
  • 7,009
  • 12
  • 59
  • 133
1

If you're getting this error for Razor in a netcoreapp3.1, you just need to change the project SDK from Microsoft.NET.Sdk.Razor to Microsoft.NET.Sdk.

Boiethios
  • 38,438
  • 19
  • 134
  • 183
1

so, try to uninstall the package entirely and install it again. make sure you do this for all the solution projects reference it. then just clean and rebuild. this worked for me.

eva
  • 89
  • 1
  • 2
1

I had a similar issue, where my project had package reference like this:

Package references:

Package A
Package B
    Package A

So because project B reference package A, I just deleted package A from the main packages list and was left with Package B referencing Package A. I rebuilt the solution and the problem was gone.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Yair A.
  • 11
  • 2
1

For me it was caused by referencing a project using a specified version of Microsoft.AspNetCore.App where my project did not :

My project :

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App"/>
  </ItemGroup>

referenced project :

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.2" />
  </ItemGroup>

Fix (My project) :

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.2" />
  </ItemGroup>
Steef
  • 569
  • 5
  • 21
0

For my project, clean and rebuild not solve my problem. After some search, I try to remove all the debug/obj folder, then rebuild and it works, wish this can help anyone who encounter this problem.

SLdragon
  • 1,477
  • 16
  • 19
0

I got the problem while trying to add "Npgsql.EntityFrameworkCore.PostgreSQL.Design" into my ASP.NET Core 7 MVC project. Here is the error I had;

Error NU1605 Detected package downgrade: NETStandard.Library from 2.0.0-preview1-25301-01 to 1.6.1. Reference the package directly from the project to select a different version.

I fixed it by adding the following line into my .csproj file;

<PackageReference Include="NETStandard.Library" Version="2.0.0-preview1-25301-01" />

Note: no line was present for this package, I copied the name and the version from the error. afterwards, do a clean and build and the error should be gone and you should be able to add whatever package you were trying to add. if error still doesn't go away, try "dotnet restore" in package manager console window.

Emre Bener
  • 681
  • 3
  • 15
-1

I just recently came across this issue and updating the NuGet packages was what worked for me.

combatc2
  • 1,215
  • 10
  • 10
-1

I solved this issue thanks to this answer. Basically, just add the following line inside the <PropertyGroup> tags in your .csproj file:

<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Shaul Behr
  • 36,951
  • 69
  • 249
  • 387