Search code examples
.net-coreentity-framework-corenugetvisual-studio-2019

Why do I get build errors when attempting to build a .NetCore 3.1 class library with EntityFrameworkCore in Visual Studio 2019?


I've got a .Net Core 3.1 created in Visual Studio 2019 (C# .Net Core library). I'm attempting to add EntityFrameworkCore thru NuGet package manager to the project. When attempting to add I got some compatibility errors.

So we created the projects and added EntityFrameworkCore on a different system. When attempting to build those project in Visual Studio 2019 on my system, I get the following errors:

Errors in Visual Studio 2019

This is a snapshot of the .Net and .NetCore runtime and sdks installed on the machine: Installed runtime and SDKs

Here are the results from dotnet restore: (Partial Listing)

Foo.WPFApp>dotnet restore Determining projects to restore... : warning NU1701: Package 'System.ComponentModel.Annotations 5.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202: Package Microsoft.EntityFrameworkCore 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.EntityFrameworkCore 5.0.0 does not support any target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202: Package Microsoft.EntityFrameworkCore.Abstractions 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.EntityFrameworkCore.Abstractions 5.0.0 does not support any target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202: Package Microsoft.Extensions.Caching.Memory 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.Extensions.Caching.Memory 5.0.0 does not support any target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202: Package Microsoft.Extensions.DependencyInjection 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.Extensions.DependencyInjection 5.0.0 does not support any target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202: Package Microsoft.Extensions.Logging 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.Extensions.Logging 5.0.0 does not support any target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] : error NU1202: Package

Here are the results from a dotnet build: (Partial Listing)

Determining projects to restore... ....csproj : warning NU1701: Package 'System.ComponentModel.Annotations 5.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project. [Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error NU1202: Package Microsoft.EntityFrameworkCore 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.EntityFrameworkCore 5.0.0 does not support any target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error NU1202: Package Microsoft.EntityFrameworkCore.Abstractions 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.EntityFrameworkCore.Abstractions 5.0.0 does not support any target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error NU1202: Package Microsoft.Extensions.Caching.Memory 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.Extensions.Caching.Memory 5.0.0 does not support any target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error NU1202: Package Microsoft.Extensions.DependencyInjection 5.0.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.Extensions.DependencyInjection 5.0.0 does not support any target frameworks. [Foo.WPFApp\Bar.WPFApp.sln] ....csproj : error

Can someone help me identify the issue and fix it?


Solution

  • 1) Try to clean nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages.

    2) disable any installed vs third party extensions under Extensions-->Manage Extensions-->Installed

    Or use devenv /safemode to start a initial vs to test whether the issue happens again.

    Also, please do not forget to delete every bin and obj folder before you install the nuget package.

    If your VS2019 version is not 16.8.X, please update it because NET5.0 is applied since 16.8.

    Besides, try to create a new net core app and then test whether the issue happens again.