Problem
Here is the basic setup of this problem:
- You created a .Net Core application and wanted to use .Net Core EF in your application for the data layer.
- You have already installed .Net Core EF from NuGet
- You setup your data layer using Fluent API
- You are ready for adding your initial migration, but using the .Net CLI keeps giving you a bogus error like the one shown below after running the following command:
dotnet ef migrations add InitialCreate
C:\Dev\YourProject.Data>dotnet ef migrations add InitialCreate The specified framework version '2.1' could not be parsed The specified framework 'Microsoft.NETCore.App', version '2.1' was not found. - Check application dependencies and target a framework version installed at: C:\Program Files\dotnet\ - Installing .NET Core prerequisites might help resolve this problem: http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409 - The .NET Core framework and SDK can be installed from: https://aka.ms/dotnet-download - The following versions are installed: 2.0.3 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.0.5 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.1.3-servicing-26724-03 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.1.4 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 2.1.5 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Gotcha
From what I have seen there are a few steps to remedy this problem and it isn’t obvious if you are new to .Net Core at all. I got most of my information by cross referencing articles and blog posts, but this one explains it well: https://github.com/dotnet/core/issues/1843
How to fix the stupid problem
Add the XML that is between the “PropertyGroup” tags to your project file that is referencing the Entity Framework NuGet package.
<PropertyGroup> <GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles> </PropertyGroup>
If at this point you were to run the “dotnet ef migrations add InitialCreate” command again you would get the following error:
C:\Dev\YourProject.Data>dotnet ef migrations add InitialCreate Your startup project 'SimpleSmtpInterceptor.Data' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.
That being said the next step according to the error is to add the missing NuGet package “Microsoft.EntityFrameworkCore.Design” to your project.
At this point when you run the “dotnet ef migrations add InitialCreate” command again you could run into more issues, but it is all first time setup of your context class. I could keep listing possibilities, but this would be a never ending article at that point, most of which is covered by google.
.Net EF Core migrations instructions
My rant you can ignore
It’s obvious .Net Core is still under developed to be having problems like this. Microsoft needs to hurry the hell up and get things up to par to .Net Framework; I feel like it’s been long enough at this point. I am never one to jump on the bandwagon early just so I can say I am doing something, especially not at the cost of inconvenience spent as time debugging their mistakes.
You saved my day, but honestly to “connect the dots” and conclude that fake error about missing *.Design package is somehow related to missing entry in .csproj file… you have to have supernatural powers :-).
Unfortunately I have had the displeasure of dealing with very similar problems in past, usually involving blowups with MSBuild. I’m glad this fixed the problem for you quickly that’s my goal with this blog. Save people time with these really annoying gremlins.
Worked like a charm. Thank you!!!!!