简体   繁体   中英

EF Core migration error with .NET Core Web API in 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:

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM