如果我在命令行中运行以下命令:dotnet ef database update --startup-project /code/spike/MyProj.Web
命令运行正常。
如果我在tasks.json
中设置这样的任务:
{
"label": "update database",
"command": "dotnet",
"type": "process",
"args": [
"ef",
"database",
"update",
"--startup-project ${workspaceFolder}/MyProj.Web"
],
"problemMatcher": "$tsc"
}
我收到以下错误:
Startup project 'MyProj.Data.csproj' targets framework '.NETStandard'. There is no runtime associated with this framework, and projects targeting it cannot 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. For more information on using the EF Core Tools with .NET Standard projects, see https://go.microsoft.com/fwlink/?linkid=2034781
有没有办法在VS Code任务中使用--startup-project
for EF Core?
大概是你从MyProj.Data项目文件夹中的命令行运行?
VS Code将在工作区文件夹级别运行任务,因此您需要添加指向MyProj.Data.csproj文件的--project arg。
此外,如果它们包含空格,VS代码会在args周围添加引号,因此您需要单独添加arg和值。
e.f.:
{
"label": "update database",
"command": "dotnet",
"type": "process",
"args": [
"ef",
"database",
"update",
"--project", "${workspaceFolder}/MyProj.Data/MyProj.Data.csproj",
"--startup-project", "${workspaceFolder}/MyProj.Web"
],
"problemMatcher": "$tsc"
}