升级Microsoft.NETCore.App至2.1.0-rc及ASP.NET Core 2.1兼容问题求助
Hey there! I get it, dealing with framework version mismatches when you're just starting out can be super frustrating. Let's break down exactly how to resolve this problem so you can get to using EF Views with ASP.NET Core 2.1.
The Root Cause
The error you're hitting happens because your project is still targeting .NET Core 2.0 (netcoreapp2.0), even after you upgraded the Microsoft.NETCore.App package. The Microsoft.AspNetCore.All 2.1.0-rc1-final package only supports projects targeting netcoreapp2.1, so NuGet blocks the installation until you update your project's target framework to match.
Step-by-Step Solution
Install the .NET Core 2.1 SDK (RC1)
First off, the reason you can't select ASP.NET Core 2.1 in Visual Studio's project creation wizard is likely because you don't have the matching SDK installed. Grab and install the .NET Core 2.1 RC1 SDK (make sure it's the same RC version as the packages you're trying to use).Update Your Project's Target Framework
You need to switch your project to target .NET Core 2.1—this is the key fix:- Right-click your project in Solution Explorer → Select Properties
- Navigate to the Application tab
- Under Target framework, pick
.NET Core 2.1(this option will show up once you've installed the SDK) - Alternatively, edit your project's
.csprojfile directly:
Replace this line:
With:<TargetFramework>netcoreapp2.0</TargetFramework><TargetFramework>netcoreapp2.1</TargetFramework>
Clean Up and Reinstall NuGet Packages
Now that your project targets the right framework, fix the package references:- Open the NuGet Package Manager, uninstall
Microsoft.AspNetCore.All 2.0.8 - Install
Microsoft.AspNetCore.All 2.1.0-rc1-final(this should work without errors now) - Or use the Package Manager Console commands:
Uninstall-Package Microsoft.AspNetCore.All Install-Package Microsoft.AspNetCore.All -Version 2.1.0-rc1-final - Quick note: For .NET Core 2.1+,
Microsoft.NETCore.Appis a framework reference, not a traditional NuGet package. You can remove the manualPackageReferencefor it in your.csproj—Visual Studio will handle it automatically once the target framework is set to 2.1.
- Open the NuGet Package Manager, uninstall
Verify and Test
Rebuild your project to make sure there are no compilation errors. You should now be able to use Entity Framework's Views functionality with ASP.NET Core 2.1.
内容的提问来源于stack exchange,提问作者Ursus Schneider

