【发布时间】:2020-07-24 13:51:36
【问题描述】:
我在 Visual Studio Code 中有两个项目的解决方案:
-
webapi项目名为 Sample.API -
classlib名为 Sample.Data 的项目
在 Sample.Data 中,我安装了这些包:
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
为简单模型创建 DbContext 并指定连接字符串后,我在执行此命令时遇到以下错误(在 Sample.Data 文件夹中):
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...
如果这是 Visual Studio,我会将 WebAPI 项目设置为启动项目。但我正在使用 VS Code。
我错过了什么?
【问题讨论】:
-
您是否尝试过使用选项
dotnet ef migrations add InitialMigration --startup-project Sample.API.csproj?这应该将项目设置为启动link
标签: c# .net-core visual-studio-code entity-framework-core asp.net-core-webapi