How to Fix Both Entity Framework Core and Entity Framework 6 Build Failed ASP.NET Core MVC

In the new ASP.NET Core MVC, the framework uses Entity Framework Core instead of Entity Framework 6. Typically if you start a new project using .NET Core you will only have one version of the Entity Framework. But if you are upgrading or adding a new project alongside classic MVC ASP.NET, then the previous version of Entity Framework is installed alongside Core. In my case, it is Entity Framework 6.

If this is the case, the old command of “Add-Migration” for creating your Code-First Migration is going to give you an error similar to below:

Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use ‘EntityFramework\Add-Migration’ for Entity Framework 6.
Build failed.DotNet Core EF Migration Add-Migration

You can go to the trouble of installing the old version of Entity Framework and that should fix the problem. However a quick workaround is to use the new commands for .NET Core — dotnet ef migrations add “InitialDBCreate” –project “MiloRiano.WebApp” -c MiloWebAppDbContext.

The command below simply uses “dotnet ef migrations add”, followed by the name of the migration and the targeted project (“–project”) in my case MiloRiano.WebApp, and the context (“-c”)  used, MiloWebAppDbContext.

This should solve your problem and have an output similar to below:

dotnet ef migrations add “InitialDBCreate” –project “MiloRiano.WebApp” -c MiloWebAppDbContext
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.2.4-servicing-10062 initialized ‘MiloWebAppDbContext’ using provider ‘Microsoft.EntityFrameworkCore.SqlServer’ with options: None
Done. To undo this action, use ‘ef migrations remove’

Hope this works for you.

Mr. Riano has worked as Manager and Senior Architect in some of the biggest firms in the world -- Accenture, Wipro, Coca-Cola.

He has architected solutions on Fortune 500 companies from Microsoft, Visa, American Express, Chevron, Shell, Novartis, Starbucks, Bill & Melinda Gates Foundation to name a few.

He has earned a B.S. in Information Technology, M.S. in Computer Science, and currently a Doctoral Candidate.

On the weekends, he coaches soccer and holds a D License from US Soccer Federation.

Previous Story

Error Visual Studio Scrapy No Module Named Win32API

Next Story

Walkthrough - Azure Labs: Automate business processes with Logic Apps

Latest from Private