37
votes

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?

9
Can you run dotnet --info and show us the result?omajid
Removing the RuntimeIdentifier worked for me too.Johnie Karr

9 Answers

40
votes

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

<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>

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

15
votes

I had a missing version in the csproj file.

Adding the version fixed the issue.

enter image description here

3
votes

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

3
votes

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" />
2
votes

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.

2
votes

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!

0
votes

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
0
votes

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 it 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 my changes.

I found a new package (nuget import) add in

MyCompany.MyProject.SomeLibraryTHREE

(and ONE and TWO had a reference to THREE)

Here was the "new" line:

<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?

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)...and changed it to to match the "3.1.0 world".

So I now had this.

<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

Not, 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.

0
votes

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