在Visual Studio代码中调试多个ASP.NET Core项目

时间:2017-04-28 15:52:24

标签: c# asp.net-core visual-studio-code

我在VS Code中有以下ASP.NET Core解决方案(solution.sln)结构:

.vscode
  launch.json
  tasks.json
src/
  api/
    api.csproj
  web/
    web.csproj
test/
  api.test/
    api.test.csproj    
solution.sln

我需要调试api.csproj和web.csproj,所以我添加了launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Api",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceRoot}/src/api/bin/Debug/netcoreapp1.1/api.dll",
      "args": [],
      "cwd": "${workspaceRoot}/src/api",
      "stopAtEntry": false,
      "console": "internalConsole"
    },
    {
      "name": "Web",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceRoot}/src/web/bin/Debug/netcoreapp1.1/Nupaya.Api.dll",
      "args": [],
      "cwd": "${workspaceRoot}/src/web",
      "stopAtEntry": false,
      "launchBrowser": {
        "enabled": true,
        "args": "${auto-detect-url}",
        "windows": {
          "command": "cmd.exe",
          "args": "/C start ${auto-detect-url}"
        },
        "osx": {
          "command": "open"
        },
        "linux": {
          "command": "xdg-open"
        }
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "sourceFileMap": {
        "/Views": "${workspaceRoot}/src/api/views"
      }
    }
  ]
} 

以下tasks.json:

{
  "version": "0.1.0",
  "command": "dotnet",
  "isShellCommand": true,
  "args": [],
  "tasks": [
    {
      "taskName": "build",
      "args": ["Api", "Web"],
      "isBuildCommand": true,
      "showOutput": "always",
      "problemMatcher": "$msCompile"
    }
  ]
}  

但是当我运行它时,我收到以下错误:

MSBUILD : error MSB1008: Only one project can be specified.

我尝试了不同的选项,但总是以某种错误结束。

有谁知道在Visual Studio Code中调试多个ASP.NET CORE项目的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

将您的tasks.json文件修改为以下内容:

{
  "version": "0.1.0",
  "command": "dotnet",
  "isShellCommand": true,
  "args": [],
  "options": {
    "cwd": "${workspaceRoot}"
  },
  "tasks": [
    {
      "taskName": "build",
      "args": [],
      "isBuildCommand": true,
      "showOutput": "always",
      "problemMatcher": "$msCompile"
    }
  ]
}

这应该构建您的整个解决方案。

要调试其中一个项目切换到Debug View,请选择一个配置,然后单击Start Debugging按钮,如下面的屏幕截图所示

debugging in vs code