在 dotnet 运行 中使用 VSCode 任务时出现问题

Issue using VSCode tasks with dotnet run

我在父文件夹中有两个项目:

parentFolder
   | webApiFolder
   | testsFolder

使用终端,我需要将 --project 参数传递给 dotnet run。因此,我认为只创建一个任务并 运行 任务会更容易。但是,我无法执行任务。

任务:

{
            "label": "run api",
            "command": "dotnet",
            "type": "process",
            "args": [
                "run",
                "--project ${workspaceFolder}\WebApi\mercury-ms-auth.csproj"
            ],
            "problemMatcher": "$msCompile"
        }

输出:

> Executing task: C:\Program Files\dotnet\dotnet.exe run --project G:\Git_CS\mercury-ms-auth\WebApi\mercury-ms-auth.csproj <

Couldn't find a project to run. Ensure a project exists in g:\Git_CS\mercury-ms-auth, or pass the path to the project using --project.
The terminal process terminated with exit code: 1

但是,如果我 运行 dotnet run --project G:\Git_CS\mercury-ms-auth\WebApi\mercury-ms-auth.csproj,那将完美地启动项目。

同样,我的 test and code coverage 任务完美运行:

{
            "label": "test with code coverage",
            "command": "dotnet",
            "type": "process",
            "args": [
                "test",
                "${workspaceFolder}/Tests/Tests.csproj",
                "/p:CollectCoverage=true",
                "/p:CoverletOutputFormat=cobertura"
            ],
            "problemMatcher": "$msCompile"
        }

一个解决方案是 "type": "shell" 并传递整个命令。

{
    "label": "run api",
    "command": "dotnet run --project ${workspaceFolder}\WebApi",
    "type": "shell",
    "problemMatcher": "$msCompile"
}