我如何在 VS Code 中 运行 EF Core `更新数据库` 任务,指定启动项目?

How can I run an EF Core `update database` task, with the startup project specified, in VS Code?

如果我 运行 在我的命令行中执行以下命令: 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 任务中为 EF Core 使用 --startup-project

大概是您从 MyProj.Data 项目文件夹中的命令行 运行ning?

VS Code 将 运行 工作区文件夹级别的任务,因此您需要添加指向 MyProj.Data.csproj 文件的 --project arg。

此外,如果参数包含空格,VS Code 会在参数周围添加引号,因此您需要分别添加参数和值。

例如:

{
    "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"
}