Your startup project doesn't reference Microsoft.EntityFrameworkCore.Design

C#Visual StudioNugetEntity Framework-Core

C# Problem Overview


I have 2 projects in my solution, I have a project with Entity Framework Core installed:

enter image description here

And in the other ASP.NET Web API project I have these packages:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.5.0.2" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Web" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.Razor" version="3.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.0" targetFramework="net461" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.4" targetFramework="net461" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="11.0.1" targetFramework="net461" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.4.1" targetFramework="net461" />
  <package id="WebGrease" version="1.6.0" targetFramework="net461" />
</packages>

When I run Add-Migration in PMC:

> Your startup project 'API' 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.

I installed Microsoft.EntityFrameworkCore.Design in the startup project instead of the data project that will contain all the entities and now it works, is this how the project should be setup?

C# Solutions


Solution 1 - C#

I found the solution here.

In short, edit your csproj file, and add to your PropertyGroup section following entry:

<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>

Solution 2 - C#

None of the options worked for me. But the one I tried on this topic worked: EF Core 3 design time migrations broken by Microsoft.EntityFrameworkCore.Design DevelopmentDependency

I just commented out the following after importing the package to the Data project:

<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5">
  <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
  <!--<PrivateAssets>all</PrivateAssets>-->
</PackageReference>

Thank you so much Microsoft by breaking the existing projects every time when you release a new .NetCore update!

Solution 3 - C#

"Your 'project name' does not refer to your startup project Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Make sure your startup project is correct, install the package and try again."

If you get this error, try 'Build > Clean Solution' in your project and then try running your command again.

This worked in my project. Or you may want to look at the documentation.

I use .Net Core 3.1 version in my project.

Solution 4 - C#

Do you have multiple projects? If yes then you have to make the host project as startup project from solution explorer and set the project as default (which project has DBContext) in PMC. Then run Add-Migration command.

Solution 5 - C#

Please make sure You have installed below packages. I was also getting same error and Installed below packages and it worked for me.

Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.Tools

Solution 6 - C#

I got this error because Visual Studio defaulted to using entity framework core rather than old-school entityframework for .NET Framework: entity framework 6. This was my solution:

EntityFramework\Update-Database

Or reference the version explicitly:

EntityFramework6\Update-Database

Also worth checking the right project is selected in the Package Manager Console. That likes to sneak back to other projects half the time!

Solution 7 - C#

There is absolutely NO reason to install Microsoft.EntityFrameworkCore.Design to your API project while having a separate Data project.

Quick solution

When using add-migration, just add a parameter to set the -StartUpProject to your Data proj (by default I presume your startup project is the API proj).


Example add-migration command below:

add-migration {migration_name} -StartUpProject {your_data_proj_name} -project {your_data_proj_name} -v

Example update-database command below:

update-database -StartUpProject {your_data_proj_name} -project {your_data_proj_name} -v

I hope this help you guys

PS: more info about the add-migration params can be found here

Solution 8 - C#

If you want to do migrations without adding EF references in your services, your library with data access needs a way to construct an instance of your DbContext. You can do this by implementing IDesignTimeDbContextFactory, example:

public class MyContextFactory : IDesignTimeDbContextFactory<MyContext>
{
    public MyContext CreateDbContext(string[] args)
    {
        var optionsBuilder = new DbContextOptionsBuilder<MyContext>();
        optionsBuilder.UseSqlServer("Data Source=MyDatabase");

        return new MyContext(optionsBuilder.Options);
    }
}

Solution 9 - C#

Try to set your web project again as startup project and this warning should go. (Right click on web project > Set as startUp project)

Solution 10 - C#

You could solve this by using below commands

dotnet tool install --global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.Design

Solution 11 - C#

This happen for me when

> Both Entity Framework Core and Entity Framework 6 are > installed. The Entity Framework Core tools are running. Use > 'EntityFramework6\Add-Migration' for Entity Framework 6.

solution was EntityFrameworkCore\Add-Migration

Solution 12 - C#

It works for me when i deleted Private Assets in .csproj or

EFCore.Design

Not making the private assets property all through the properties of the package

Solution 13 - C#

Click on startup project name and remove this:

<PrivateAssets>all</PrivateAssets> 

from package reference Microsoft.EntityFrameworkCore.Design.

Solution 14 - C#

Set the project with entities as the Startup project and run the scaffolding command. it worked for me. Don't forget to revert the startup project after.

Solution 15 - C#

I had the same issue while I had more than one project in the solution. the mistake I was doing was I had not selected the concerned project as the Default project in Package Manager Console. So check if you have selected the same project as default in Package Manager Console in which you want to run migration command.

Solution 16 - C#

In order for the migration tool to work, I had to add the Microsoft.VisualStudio.Web.CodeGeneration.Design NuGet package as well.

Solution 17 - C#

For anyone stuck on this issue with EF Core Design installed, I simply unloaded and reloaded the project to solve the problem.

Right click the project in the Solution Explorer, unload the project, then right click again to reload.

Now it should recognize Entity Framework Core Design.

Solution 18 - C#

It works for me when I delete PrivateAssets in the .csproj app

Solution 19 - C#

More a workaround than a solution, I ended up unloading the startup project from the solution. Ran the migration, added the project back to the solution. I don't expect to have many migrations, so it worked for me. What baffles me is that I have a solution with similar features and I didn't have the same issue.

Solution 20 - C#

First install the "microsoft.entityframeworkcore.design" better to install it using the nuget from the Package Manager Console and the command is: Install-Package Microsoft.EntityFrameworkCore.Design -Version x.x.x the link to the nuget package is this link

Then rebuild the solution after installing the required DLL, you might need to install other dependencies after that, but at least you will be done with the "microsoft.entityframeworkcore.design" dependency

Solution 21 - C#

Please make sure you have installed the same version of the packages below:

  1. Microsoft.EntityFrameworkCore.SqlServer
  2. Microsoft.EntityFrameworkCore.Design

I was also getting the same error and re-installed the packages with the same version and it worked for me.

Solution 22 - C#

What solved it for me was to have the same version of Microsoft.EntityFrameworkCore.Design and Microsoft.EntityFrameworkCore.SqlServer packages, which in my case was 2.1.14

Edit 1: This was solved using a

<Project Sdk="Microsoft.NET.Sdk.Web">

on

<TargetFramework>net5.0</TargetFramework>

Solution 23 - C#

There is one more reason to get this error (even if you changed PrivateAssets) - if your startup project is not referenced to data access project. So if you just created new projects it can be possible case

Solution 24 - C#

you need to install the design package of Microsoft EntityFrameworkCore. run this command

> dotnet add package Microsoft.EntityFrameworkCore.Design

this will include package in .csproj file

Solution 25 - C#

Another cause of this is simply I was completely missing the package Microsoft.EntityFrameworkCore.Tools package, which became uninstalled somehow.

It's worth noting that the error I got for this was similar but different and was "Your target project 'XXX' doesn't reference EntityFramework. This package is required for the Entity Framework Core Tools to work. Ensure your target project is correct, install the package, and try again."

Installing it got me back on track.

Solution 26 - C#

just remove all and run the command again worked for me

Solution 27 - C#

I had this same problem and I found out that the cause was that I installed Misoft.EntityFrameworkCore, Misoft.EntityFrameworkCore.SqlServer and Misoft.EntityFrameworkCore.Tools all in my Data Layer (in one project), remember we have multiple projects (Multiple Tier), and i set one of the projects as the StartUp. So my solution was to uninstall Misoft.EntityFrameworkCore.SqlServer and Misoft.EntityFrameworkCore.Tools from the Data layer (that is the project where I have my DbContext) and install them (Misoft.EntityFrameworkCore.SqlServer and Misoft.EntityFrameworkCore.Tools) in the Dependencies of StartUp project.

HOW TO INSTALL Right click on the Dependencies in the StartUp project, select: Manage NuGet Packages.. Click install and search the above two packages.

Projects in the Application Image of how it should look after following the below steps

Solution 28 - C#

Install this Nuget Package --> Microsoft.EntityFrameworkCore.Design

And run migrations again

enter image description here

Solution 29 - C#

You can re-check what is the current startup project? You might have to set NuGet Package Manager Console's Default Project to where you installed that package means in Data project and it will be solved for you.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionel_pup_leView Question on Stackoverflow
Solution 1 - C#astrowalkerView Answer on Stackoverflow
Solution 2 - C#thusView Answer on Stackoverflow
Solution 3 - C#Ahmet TınastepeView Answer on Stackoverflow
Solution 4 - C#vivek nunaView Answer on Stackoverflow
Solution 5 - C#Kiran KardelView Answer on Stackoverflow
Solution 6 - C#noelicusView Answer on Stackoverflow
Solution 7 - C#AndonovView Answer on Stackoverflow
Solution 8 - C#Edwin van der ThielView Answer on Stackoverflow
Solution 9 - C#Anuj ShuklaView Answer on Stackoverflow
Solution 10 - C#Kavinda SenarathneView Answer on Stackoverflow
Solution 11 - C#Abdullah TahanView Answer on Stackoverflow
Solution 12 - C#Kadir TuranView Answer on Stackoverflow
Solution 13 - C#مؤمل ماجد سلمانView Answer on Stackoverflow
Solution 14 - C#ShivankaView Answer on Stackoverflow
Solution 15 - C#waqar haiderView Answer on Stackoverflow
Solution 16 - C#PJ3View Answer on Stackoverflow
Solution 17 - C#SidGabrielView Answer on Stackoverflow
Solution 18 - C#dat trieuView Answer on Stackoverflow
Solution 19 - C#JayJayView Answer on Stackoverflow
Solution 20 - C#ibrView Answer on Stackoverflow
Solution 21 - C#Toqeer YousafView Answer on Stackoverflow
Solution 22 - C#duartegjmiguelView Answer on Stackoverflow
Solution 23 - C#DmitriView Answer on Stackoverflow
Solution 24 - C#balan kuganView Answer on Stackoverflow
Solution 25 - C#Mike UpjohnView Answer on Stackoverflow
Solution 26 - C#Sky3ootView Answer on Stackoverflow
Solution 27 - C#CeeView Answer on Stackoverflow
Solution 28 - C#Sydney_devView Answer on Stackoverflow
Solution 29 - C#Mayur NarkhedeView Answer on Stackoverflow