7

When I go into Tools | NuGet Package Manager | Manage NuGet Package for Solution, it shows me there are 12 updates available.

But when I attempt to update them all, I get errors.

NU1202: Package Microsoft.VisualStudio.Web.CodeGeneration 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.VisualStudio.Web.CodeGeneration 5.0.0 supports: net5.0 (.NETCoreApp,Version=v5.0)
NU1202: Package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore 5.0.0 supports: net5.0 (.NETCoreApp,Version=v5.0)
NU1202: Package Microsoft.VisualStudio.Web.CodeGeneration.Utils 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.VisualStudio.Web.CodeGeneration.Utils 5.0.0 supports: net5.0 (.NETCoreApp,Version=v5.0)
NU1202: Package Microsoft.VisualStudio.Web.CodeGeneration.Contracts 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.VisualStudio.Web.CodeGeneration.Contracts 5.0.0 supports: net5.0 (.NETCoreApp,Version=v5.0)
NU1202: Package Microsoft.VisualStudio.Web.CodeGenerators.Mvc 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.VisualStudio.Web.CodeGenerators.Mvc 5.0.0 supports: net5.0 (.NETCoreApp,Version=v5.0)
Package restore failed. Rolling back package changes for 'SolutionName'.

I can see there are incompatibility issues between .NET Core 3.1 and .NET 5.0 but I don't know why.

Why is NuGet Package Manager trying to add .NET 5.0 updates to a .NET Core 3.1 application?

janw
  • 5,204
  • 5
  • 24
  • 43
Jonathan Wood
  • 59,750
  • 65
  • 229
  • 380

4 Answers4

7

Why is NuGet Package Manager trying to add .NET 5.0 updates to a .NET Core 3.1 application?

.NET 5.0 is the next major release of .NET Core following 3.1. After the .NET 5.0 releasing, we could install the .NET 5.0 version packages via the Nuget Package Manager, Or update an existing ASP.NET Core 3.1 project (and the packages) to ASP.NET 5.0. So, when we open the .Net Core 3.1 application's Nuget Package Manager, we will see these Updates for the latest version:

enter image description here

Then, if we click the Update button to update these packages, it will show the not compatible error. Because, at present, our application is still targeted to the Asp.net Core 3.1 version, instead of .NET 5.0.

To solve this issue, you can ignore these Updates, and still using the 3.* version package for the Asp.net Core 3.1 application.

Otherwise, you can update an your ASP.NET Core 3.1 project to ASP.NET Core 5.0 (Before updating, please make sure you have installed .NET 5.0 and upgrade the Visual Studio version to the latest version).

Right click the Project and click the Properties option, change the Target FrameWork from .NET Core 3.1 to .NET 5.0. Save the change, then, click the Update button in the NuGet to update the packages.

enter image description here

[Note] When update the packages, please try to update them one by one (instead of Select all packages and click the Update button), because, they might contain dependencies.

Zhi Lv
  • 10,958
  • 1
  • 6
  • 16
  • 3
    Of course I understand .NET 5 is the new version, but my application is set to .NET Core 3.1. Why are .NET 5 libraries being installed in a .NET Core application when they are not compatible? – Jonathan Wood Nov 24 '20 at 02:23
  • I will go over your other comments in more detail when I'm at my computer. – Jonathan Wood Nov 24 '20 at 02:24
  • `Why are .NET 5 libraries being installed in a .NET Core application when they are not compatible?` For the .NET Core 3.1 application, in the NuGet Package Manager, it just shows that there has some package which have updates, it will not auto update these packages to the latest version (.NET 5 version). If you try to click the update button to update these packages to the .NET 5 version, since they are not compatible, it will show the not compatible error, and prevent the updates. Update or Not Update depends on your choice. – Zhi Lv Nov 25 '20 at 01:47
  • Look at the error messages. It did try to install the .NET 5 packages and I got errors because they were not compatible. I just checked the checkbox at the top to select them all and clicked Update. It actually attempted to install them before getting the error. Why am I getting update alerts for versions not compatible with my application? – Jonathan Wood Nov 25 '20 at 02:03
  • Okey, I understand your meaning. Do you mean the NuGet package manager should detect the application target framework version and then based on the target version to update packages. As far as I know, this is the NuGet Package Manager tool's default behavior, NuGet will list all the packages need to update, without detecting whether the new version packages are compatible with the current application or not. So, if we install the not compatible packages, it will show this error. I suggest you could feedback this detect and update issue to [NuGet forum](https://github.com/NuGet/Home/issues/). – Zhi Lv Nov 25 '20 at 03:26
  • 1
    Correct. I actually posted in the asp.net core repository on GitHub. It is recognized as an issue that will be addressed. https://github.com/dotnet/aspnetcore/issues/28098 – Jonathan Wood Nov 25 '20 at 03:30
1

if you use visual studio 2019 as an editor go to project settings.

Application ----> Target framework -----> .NET 5.0

the problem will be solved.

0

In my case, downgrading to a previous version didn't work. The nuget restore was being run on Azure DevOps on version 4.1. Bumping the nuget to version 5.8.1 did the trick.

0

I encountered the same problem. In my case updating my visual studio to the latest version and then upgrading projects target framework to .NET 5.0 did work.

Chris Catignani
  • 3,857
  • 6
  • 29
  • 40