How to Run two .net core apps with debugging On using Visual Studio Code ?

When developing a web application we separate our application with *.web being initial server-side application and  *.api application which will help us fetch/update data for client-side operations and avoid page reloads.


Photo by Vincent van Zalinge on Unsplash

Here is .NET Core application I was working on which had a similar kind of ask, and I wanted to use VSCode to debug my application.

This is how we do it, first, we need to create a solution so that we keep both the API and Web project in one place

dotnet new sln -n appname
dotnet sln add src/appname/appname.web.csproj
dotnet sln add src/appname/apname.api.csproj

Open "launch.json" and Click on add configuration and add then select

.NET Core Launch (web) 

No go ahead and rename to web or web-api, also add a development URL with a different than web configs the "env" property

"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "https://localhost:5001"
}

Done now just run each of the configs with debug mode and happy debugging!

For reference adding the complete launch.json

{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web-api)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/serviceflow.api/bin/Debug/netcoreapp2.2/serviceflow.api.dll",
"args": [],
"cwd": "${workspaceFolder}/serviceflow.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",
"ASPNETCORE_URLS": "https://localhost:5001"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/serviceflow.web/bin/Debug/netcoreapp2.2/serviceflow.web.dll",
"args": [],
"cwd": "${workspaceFolder}/serviceflow.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",
"ASPNETCORE_URLS": "https://localhost:6001"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
},
]
}
view raw launch.json hosted with ❤ by GitHub

Comments

Popular posts from this blog

Launch .Net Core with VSCode for starters

Protecting sensitive data using Secret Manager in .Net Core