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

98,375

Solution 1

I found the solution here.

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

<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>

Solution 2

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

"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

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

Package Manager Console screenshot:

enter image description here

Solution 5

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
Share:
98,375

Related videos on Youtube

el_pup_le
Author by

el_pup_le

ಠ_ಠ

Updated on May 12, 2022

Comments

  • el_pup_le
    el_pup_le almost 2 years

    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?

    • milan
      milan over 5 years
      If your DB context project is not the same as entry project you need to add entry project location when adding migration, e.g. dotnet ef migrations add initialMigration -s ../MainProjectLocation/ --context MyDbContext.
    • vivek nuna
      vivek nuna over 5 years
      Do you have multiple projects? If yes then you have to make the host project as startup project and set the project as default (which project has DBContext) in PMC
    • el_pup_le
      el_pup_le over 5 years
      @milan I'm not using dotnet ef, I'm using Microsoft.EntityFrameworkCore
    • el_pup_le
      el_pup_le over 5 years
      @CodeCaster should I install all packages in the startup project? Why does it want the design package installed in the startup project?
    • Jack Zhai-MSFT
      Jack Zhai-MSFT over 5 years
      You need Microsoft.EntityFrameworkCore.Tools for running PM-Console commands, but the specific packages like Microsoft.EntityFrameworkCore.Design was necessary for Microsoft.EntityFrameworkCore.Tools to work, I think it was normal for it, anyway, you have resolved this issue.
    • nam
      nam over 4 years
      @el_pup_le I got the exact same message on my project. Following the instructions on the message, I ran Install-Package Microsoft.EntityFrameworkCore.Design in the PM Console and everything started working fine.
    • user692942
      user692942 over 3 years
      So much misinformation in this thread, save yourself the trouble and remove <PrivateAssets>all</PrivateAssets> from the package reference in the .csproj file from Microsoft.EntityFrameworkCore.Design for your infrastructure project.
    • ZakDaniels99
      ZakDaniels99 about 2 years
      Removing<PrivateAssets>all</PrivateAssets> is most definitely not the right solution to this! You don't want Microsoft.EntityFrameworkCore.Design to get published along with your code (see this link for details). To fix this, make sure you set the project containing your db context as both the default and start up project in your Package Manager Console and make sure you override your OnConfiguring method in your db context so a default connection string is supplied.
  • Cristina Carrasco
    Cristina Carrasco over 4 years
    I just want to add if you are using EF 6 the correct command is: EntityFramework6\Add-Migration, that solve the problem for me. Thanks.
  • Renato Medeiros
    Renato Medeiros about 4 years
    This worked for me. Note that this should be placed in the project that you're referencing the Entity Framework, if you have multiple projects. You might need to remove <PrivateAssets>all</PrivateAssets> from some packages references (I removed from <PackageReference Include="Microsoft.EntityFrameworkCore.Design" and <PackageReference Include="Microsoft.EntityFrameworkCore.Tools"
  • GrzegorzM
    GrzegorzM about 4 years
    Thanks @RenatoMedeiros, removing PrivateAsserts = all from Design project solved this issue. I don't even need GenerateRuntimeConfigurationFiles setting!
  • Lab Lab
    Lab Lab almost 4 years
    @RenatoMedeiros You need to post it as an answer, as it helped me solve my problem!
  • mruanova
    mruanova almost 4 years
    Thank you, this worked for me: 'dotnet add package Microsoft.EntityFrameworkCore.Design' source docs.microsoft.com/en-us/ef/core/get-started/install
  • user692942
    user692942 over 3 years
    Adding the package doesn't help keep the EF assembly separate, which is entirely possible the issue is the use of <PrivateAssets>all</PrivateAssets> in the csproj is hiding the assembly from being accessed by the startup project.
  • user692942
    user692942 over 3 years
    Again, doing this isn't a solution. It just ends up adding EF assemblies into a startup project that should be entirely separate from the infrastructure (separation of concerns). This is the correct answer which removes the <PrivateAssets>all</PrivateAssets> in the infrastructure assembly .csproj file.
  • user692942
    user692942 over 3 years
    Again, doing this isn't a solution. It just ends up adding EF assemblies into a startup project that should be entirely separate from the infrastructure (separation of concerns). This is the correct answer which removes the <PrivateAssets>all</PrivateAssets> in the infrastructure assembly .csproj file.
  • Cubelaster
    Cubelaster over 3 years
    This also worked for me. However, what are further consequences of this?
  • RamWill
    RamWill over 3 years
    I am using a solution where efcore is a seperate project, your answer worked for me
  • Ludvig W
    Ludvig W over 3 years
    I replaced "all" with "none" instead which I think is more appropriate, but the answer helped me find the solution, thanks! Here is some more info for anyone who wana investigate further how PrivateAssets work: docs.microsoft.com/en-us/dotnet/core/tools/csproj
  • João Ignacio
    João Ignacio about 3 years
    Same for me, just by removing <PrivateAssets>all</PrivateAssets> it worked!
  • Alex
    Alex about 3 years
    Thanks, this resolved it for me too! Here's a related issue on github: github.com/dotnet/Scaffolding/issues/711
  • hatem87
    hatem87 about 3 years
    Funny Microsoft bug as usual. Setting the project as startup project in the solution resolve the isssue. Thank you @Shivanka
  • Muhammad Zaheer Nazir
    Muhammad Zaheer Nazir about 3 years
    I have not done anything mentioned in other answers, just Cleaning the solution and the main project is using .net core 3.1. It worked for me.
  • xpirrr
    xpirrr about 3 years
    GenerateRuntimeConfigurationFiles tag not resolved my issue but this works on me.
  • Nicole
    Nicole almost 3 years
    Thank you, that worked for me. What I would like to know is why this is necessary even when I am running the Add-Migration command from the package manager console with the right project selected as target.
  • vivek nuna
    vivek nuna almost 3 years
    @Nicole please check this link stackoverflow.com/a/12031921/6527049
  • joedotnot
    joedotnot almost 3 years
    what about Microsoft.EntityFrameworkCore, is that required also ?
  • Cubelaster
    Cubelaster almost 3 years
    Hahaha, I'm using this answer for the third time... Thank you!
  • luizs81
    luizs81 over 2 years
    Worked for me. However, the Nuget package has now this yellow triangle, as something is not right. I'm wondering why is that. It's not a big deal but it bothers me a bit.
  • Andre
    Andre over 2 years
    At witch place can you run this command? CMD does not know EntityFramework as command
  • noelicus
    noelicus over 2 years
    @Andre Package Manager console in Visual Studio.
  • Admin
    Admin almost 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
  • Matt
    Matt almost 2 years
    This didn't solve the issue for me. The error still occurs.
  • GoWiser
    GoWiser almost 2 years
    @viveknuna What exactly do you mean 'set the project as default in PMC'?
  • vivek nuna
    vivek nuna almost 2 years
    @GoWiser I have added a screenshot to show the default project in my answer, you can check.
  • Gert Arnold
    Gert Arnold almost 2 years
    What is "all"? One-liners are rarely helpful.
  • GoWiser
    GoWiser almost 2 years
    Do you know how to write the same commands in CMD, ie. detnet ef ....?
  • GoWiser
    GoWiser almost 2 years
    @viveknuna I was just curious, I use CMD/Bash only, not powershell. I have no idea if your solution works. I upvoted your comment. None of the solutions found on stackoverflow for multi project (database design in one project, usage of database design in another) worked for me - I also need to setup devops pipeline for automatic deployment of migrations.
  • jorel
    jorel almost 2 years
    This solution worked for my where I had EF related code in a separate class library.