Solvedomnisharp vscode Debug multiple ASP.NET Core projects in Visual Studio Code

Moved from microsoft/vscode#25628
From @mdmoura


  • VSCode Version: 1.11.2
  • OS Version: Windows 10

I have the following ASP.NET Core solution (solution.sln) structure in VS Code:

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

I need to debug both api.csproj and web.csproj so I added the 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"
      }
    }
  ]
} 

And the following tasks.json:

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

But when I debug it I get the following error:

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

I have tried different options but I always end with some kind of error some not even related with MSBUILD.

What is the proper way to debug multiple ASP.NET CORE projects in Visual Studio Code?

18 Answers

✔️Accepted Answer

Try this also

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Portal",
            "type": "coreclr",
            "request": "launch",
            "program": "/Users/jonathan/Projects/vq/src/VQPortal.Hosting.Self/bin/Debug/netcoreapp1.1/VQPortal.Hosting.Self.dll",
            "args": [],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": false,
            "externalConsole": false
        },
        {
            "name": "Debug VQConsole",
            "type": "coreclr",
            "request": "launch",
            "program": "/Users/jonathan/Projects/vq/src/VQConsole/bin/Debug/netcoreapp1.1/VQConsole.dll",
            "args": [],
            "cwd": "${workspaceRoot}",
            "stopAtEntry": false,
            "externalConsole": false
        }
    ],
    "compounds": [
        {
            "name": "Debug VQConsole & Portal",
            "configurations": [
                "Debug VQConsole",
                "Debug Portal"
            ]
        }
    ]
}

Other Answers:

Thanks @jchannon and @DustinCampbell !
I was looking for a solution for debugging two projects at same time, and found this thread.

Steps:
a) I created a solution for build my web projects, because i´ve a windows forms project also.

b) Then on tasks.json, i´ve pointed to my solution on args value:

{
  "version": "0.1.0",
  "command": "dotnet",
  "isShellCommand": true,
  "args": [],
  "tasks": [
    {
      "taskName": "build",
      "args": ["${workspaceRoot}/slnTcsErpFullDesenvWeb.sln"],
      "isBuildCommand": true,
      "problemMatcher": "$msCompile"
    }
  ]
}

c) And on my launch.json:

{
  "version": "0.2.0",
  "configurations": [
      {
      "name": "Tcs View Web Development",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${workspaceRoot}/Tcs.Erp.UI.Web/bin/Debug/netcoreapp2.0/Tcs.Erp.UI.Web.dll",
      "args": [],
      "cwd": "${workspaceRoot}/Tcs.Erp.UI.Web",
      "stopAtEntry": false,
      "internalConsoleOptions": "openOnSessionStart",
      "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}/Views"
      }
    },
    {
      "name": "Tcs Api Development",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program":
        "${workspaceRoot}/Tcs.Erp.Api/bin/Debug/netcoreapp2.0/Tcs.Erp.Api.dll",
      "args": [],
      "cwd": "${workspaceRoot}/Tcs.Erp.Api",
      "stopAtEntry": false,
      "internalConsoleOptions": "openOnSessionStart",
      "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}/Views"
      }
    },
    {
      "name": ".NET Core Attach",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:pickProcess}"
    }
  ],
  "compounds": [
    {
      "name": "Debug Tcs View and API Dev Mode",
      "configurations": [
        "Tcs View Web Development",
        "Tcs Api Development"
      ]
    }
  ]
}

More Issues: