49

I try to update my .net solution from .NET Core 1.1 to .NET Core 2.1. I have several .NET Core and .NET standard projects inside, which reference each other and another NuGet packages. After update 'dotnet resore' and 'dotnet build' commands work fine, but when i try to build my solution from visual studio, i get this error:

Error NU1605 Detected package downgrade: Microsoft.NETCore.App from 2.1.3 to 2.1.0. Reference the package directly from the project to select a different version.

And i see that indeed some of my projects have SDK reference to Microsoft.NETCore.App v2.1.0 and some of them v.2.1.3. Setting RuntimeFrameworkVersion and adding this package to dependencies explicitly doesn't work.

How i can deal with this?

UPD: dotnet --info:

.NET Core SDK (reflecting any global.json):  Version:   2.1.401  Commit:    91b1c13032

Runtime Environment:  OS Name:     Windows  OS Version:  10.0.17134  OS Platform: Windows  RID:         win10-x64  Base Path:   C:\Program Files\dotnet\sdk\2.1.401\

Host (useful for support):   Version: 2.1.3   Commit:  124038c13e

.NET Core SDKs installed:
  1.1.10 [C:\Program Files\dotnet\sdk]
  2.0.0 [C:\Program Files\dotnet\sdk]
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.100 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.400 [C:\Program Files\dotnet\sdk]
  2.1.401 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:   Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]   Microsoft.AspNetCore.All 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]   Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]   Microsoft.AspNetCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]   Microsoft.NETCore.App
1.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]   Microsoft.NETCore.App 1.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]   Microsoft.NETCore.App
2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]   Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]   Microsoft.NETCore.App
2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]   Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]   Microsoft.NETCore.App
2.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:   https://aka.ms/dotnet-download

UPD: Somehow issue disappears if i remove this line from .csproj file:

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

Can it be related?

ant
  • 1,107
  • 2
  • 12
  • 23

10 Answers10

45

I had a similar issue to you. Could not publish my project when I specified a runtime identifier.

The solution I got to work was to add in the following line to the *.csproj

<PropertyGroup>     
    <TargetFramework> xxx </TargetFramework>     
    <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>  <<<----- Add this line  
</PropertyGroup>

After that line was added the project would publish correctly.

The below link references a downgrade issue between 2.1.1 and 2.1.0 but the solution worked the same.

https://github.com/dotnet/cli/issues/9624

Moradnejad
  • 3,466
  • 2
  • 30
  • 52
Soul3lade
  • 548
  • 5
  • 10
17

I had a missing version in the csproj file.

Adding the version fixed the issue.

enter image description here

h-rai
  • 3,636
  • 6
  • 52
  • 76
  • 8
    This will change the behavior. This way you won't have roll forward anymore, the recommended way by Microsoft is to have a versionless Microsoft.AspNetCore.App and to have the SDK at top be `` – Rutix Jul 11 '19 at 07:55
5

I just experienced this same issue after adding a reference to MySQL.Data.

The only solution was to explicitly define the version of the affected references in the .csproj file:

<PackageReference Include="System.Diagnostics.Debug" Version="4.3.0" />
<PackageReference Include="System.Runtime.Extensions" Version="4.3.0" />
<PackageReference Include="System.Globalization" Version="4.3.0" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
xfx
  • 1,329
  • 8
  • 18
4

After updating .net core SDK on my windows machine from .net core 2.1.0 to .net core 2.2.0 I had the same issue. I was unable to build the project and getting build error with Detected package downgrade: Microsoft.AspNetCore.Razor.Design from 2.2.0 to 2.1.0.

I have resolved this issue by updating a nuget package for Microsoft.AspNetCore.Razor.Design

Niraj Trivedi
  • 2,370
  • 22
  • 24
  • This fixed it for me. Strange that Microsoft.AspNetCore.App was already upgraded to 2.2 but [...].Razor.Design was left to 2.1 – Pat Feb 11 '19 at 18:42
  • IMHO the most correct answer since Microsoft recommends it as a solution: https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1605 – Evgeny Gorb Jun 25 '22 at 06:43
3

I had this issue as well. What ultimately fixed it for me was uninstalling the .NET SDK 2.1.3 from the "Programs" control panel. Or I basically had to uninstall any later versions of the related SDK libraries that my project was trying to use.

sean
  • 1,187
  • 17
  • 25
2

My version of this issue (I think) was caused by a combination of actual .NET Core versions installed on a Jenkins build server alongside a Unit Test project having ambigious references.

I understand that, in an ideal world, dotnet expects no version stated in the csproj for AspNetCore - providing maximum flexibility during build:

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

However, on the build server when it compiled the main project (first), it chose to use 2.1.6 as the AspNetCore version. It then tries to compile the test project, and that project had a minimum version of "2.1.1", so build process tries to downgrade and then aborts the build as a fail.

I removed the "2.1.1" minimum version from the test project, but then the test project would not build locally because it could not resolve the dependencies unambigiously. After a number of NuGet package upgrades / downgrades no joy, so chose to force a "2.1.6" minimum version so align with build server.

This still could not resolve locally all the dependencies correctly, and finally ended up with forcing the minimum version for NetCore as well:

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.6" />
<PackageReference Include="Microsoft.NetCore.App" Version="2.1.6" />

Everything now built locally and on the Jenkins build server!

From Orbonia
  • 616
  • 5
  • 16
2

For future readers.

So early in the morning, my code was building.

Then I started getting this error:

Error   NU1605  Detected package downgrade: Microsoft.Extensions.Logging from 3.1.1 to 2.1.1. Reference the package directly from the project to select a different version.

and I got this error report on 2 assemblies,csprojs.

MyCompany.MyProject.SomeLibraryONE 
MyCompany.MyProject.SomeLibraryTWO

So of course, I started tracking down "Microsoft.Extensions.Logging".

But then I remembered "It was working this morning", and I back tracked to simply identity my changes I had made from the morning.

I found a new "PackageReference" (via nuget import) added in ... to a csproj:

MyCompany.MyProject.SomeLibraryTHREE

(and SomeLibraryONE and SomeLibraryTWO had a reference to SomeLibraryTHREE)

Here was the "new" line: (that was added to MyCompany.MyProject.SomeLibraryTHREE)

<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.1" />

So I looked and looked, but this was the ONLY place "Microsoft.Extensions.Http" package was being imported.

Do what? (this "do what" and "huh" thought is from the original error message that mentions '2.1.1'..but I had nothing going on in the 2.x world) ??

From memory, I just kinda remembered that I had alot of "3.1.0" package imports, but no 3.1.1.

examples of OTHER package imports (for example):

<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />

Long story:short..............I changed that new package import (the new import was the prime-suspect in my code breakage in SomeLibraryTHREE)...and changed it to to match the "3.1.0 world".

So I now had this (in MyCompany.MyProject.SomeLibraryTHREE).

<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.0" />

And now everything works.

So the (actual) error could be a red-herring to what is actually happening.

Hopefully you're using source control, and can "reverse" step it.

Just to finish this out...here is the the weird part:

\.nuget\packages\microsoft.extensions.http\3.1.1\lib\netcoreapp3.1\Microsoft.Extensions.Http.dll

I opened up this file.

and it references

// Microsoft.Extensions.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
    // Assembly reference loading information:
    // Info: Success - Loading from: C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\3.1.0\Microsoft.Extensions.Logging.dll

Note, it is "3.1.0\Microsoft.Extensions.Logging.dll". So what is it breaking stuff????? (Who knows?)

so while it doesn't make sense to me...........what I showed above did address the issue.

Go figure.

Hope that helps someone.

granadaCoder
  • 26,328
  • 10
  • 113
  • 146
1

I also had this problem after installing a new version of .Net Core (2.0 to 2.1). The below link gave me a hint of what caused the problem.

https://github.com/dotnet/cli/issues/9433

The solution for me was to change the project's Target Framework to the latest installed .Net Core version.

Project Properties > Application > Target Framework
leosbrf
  • 159
  • 2
  • 15
0

I am on .NET 5 and looks like this bug is still there.

Issue: Unable to update EntityFramework package from 5.0.5 to 5.0.8.

Fix:

  1. One quick workaround I found is to remove all package references for the selected package(version 5.0.5 in my case) from Solution>References>Packages. Right click and remove each one.

  2. Now go to nuget package manager and add these same packages again(now the version will be 5.0.8).

  3. Build

Swanand Pangam
  • 858
  • 1
  • 10
  • 25
0

I had a very similar error and the solution was to add this to my .csproj

<ItemGroup>
    <PackageReference Include="Microsoft.NETCore.Targets" Version="3.0.0" PrivateAssets="all" />
</ItemGroup>
cblanto7
  • 168
  • 1
  • 3
  • 12