DEV Community

Cover image for How to Run two .net core apps with debugging On using Visual Studio Code?
Arjun Shetty
Arjun Shetty

Posted on

4 3

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 we provide a *.api application which will help us fetch/update data for client-side operations and avoid page reloads.

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

Photo by Vincent van Zalinge on Unsplash
Originally blogged on Blogger

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs