How to Build and Debug multiple .NET projects in Visual Studio Code (vscode)
Suppose we have mutliple projects with a structure like this :
- src
- SampleProject.Api
- SampleProject.Api.csproj
- SampleProject.Console
- SampleProject.Console.csproj
- SampleProject.Lib
- SampleProject.Lib.csproj
Note that we don't have a solution file here. But with a solution, it's not very different.
- Create a directory named
.vsocde
in your working directory root. - Create a file inside
.vscode
and name ittasks.json
-> task.json - Create another file inside
.vscode
and name itlaunch.json
-> launch.json
For debugging .NET application we must install omnisharp
plugin on vscode.
{
"version": "2.0.0",
"tasks": [
{
"label": "build Lib",
"command": "dotnet",
"type": "shell",
"args": [
"build",
"${workspaceFolder}/src/SampleProject.Lib"
],
"problemMatcher": [
"$msCompile"
],
"presentation": {
"reveal": "always"
},
"group": "build"
},
{
"label": "build Api",
"command": "dotnet",
"type": "shell",
"args": [
"build",
"${workspaceFolder}/src/SampleProject.Api"
],
"problemMatcher": "$msCompile",
"presentation": {
"reveal": "always"
},
"group": "build"
},
{
"label": "build Console",
"command": "dotnet",
"type": "shell",
"args": [
"build",
"${workspaceFolder}/src/SampleProject.Console"
],
"problemMatcher": "$msCompile",
"presentation": {
"reveal": "always"
},
"group": "build"
}
]
}
{
"configurations": [
{
"name": "Api",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build Api",
"program": "${workspaceFolder}/src/SampleProject.Api/bin/Debug/net6.0/SampleProject.Api.dll",
"args": [],
"cwd": "${workspaceFolder}/src/SampleProject.Api",
"stopAtEntry": false,
"console": "externalTerminal"
},
{
"name": "Console",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build Console",
"program": "${workspaceFolder}/src/SampleProject.Console/bin/Debug/net6.0/SampleProject.Console.dll",
"args": [],
"cwd": "${workspaceFolder}/src/SampleProject.Console",
"stopAtEntry": false,
"console": "integratedTerminal"
}],
"compounds": [
{
"name": "Debug All",
"configurations": [
"Api",
"Console"
]
}
]
}
Now we can go to Debug
tab and debug one or all our applications we already definded in launch.json
file.