EF Core migration error with .NET Core Web API in Visual Studio Code

.net-core asp.net-core-webapi c# entity-framework-core visual-studio-code


I have a solution with two projects inside Visual Studio Code:

  • webapi project called Sample.API
  • classlib project called Sample.Data

In Sample.Data, I have these packages installed:


After creating a DbContext for a simple model and specifying the connection string, I run into the following error when executing this command (Inside the Sample.Data folder):

dotnet ef migrations add InitialMigration

Startup project 'Sample.Data.csproj' targets framework '.NETStandard'.
There is no runtime associated with this framework, and projects targeting it can't be executed directly.
To use the Entity Framework Core .NET Command-line Tools with this project, add an executable project
targeting .NET Core or .NET Framework that references this project, and set it as the startup project
using --startup-project; or, update this project to cross-target .NET Core or .NET Framework...

If this was Visual Studio, I would set the WebAPI project as the startup project. But I'm using VS Code.

What am I missing?

4/11/2020 8:54:29 PM

Popular Answer

Thank you @sea_ocean ... You have to specify the startup project:

dotnet ef migrations add MigrationOne --startup-project ../Sample.API/Sample.API.csproj

and then

dotnet ef database update --startup-project ../Sample.API/Sample.API.csproj

You also need to install Microsoft.EntityFrameworkCore.Design to the startup project

4/12/2020 12:29:56 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow