Debugging Multiple .NET Core Projects in VS Code
Tags: dotnet, vscode, debugging, csharp
Published: 2020-10-13 21:37:42

---
title: Debugging Multiple .NET Core Projects in VS Code
published: true
date: 2020-10-13 21:21:04 UTC
tags: dotnet, vscode,debugging,csharp
canonical_url: https://wakeupandcode.com/debugging-multiple-net-core-projects-in-vs-code/
---

# Introduction

Originally written up in a GitHub repo while helping out another developer, this blog post explains how you can debug multiple .NET Core projects in Visual Studio Code.

To download the sample code, clone the following GitHub repository:

- [https://github.com/shahedc/multiweb](https://github.com/shahedc/multiweb)

## Opening VS Code

Launch VS Code with the project root as the current working directory. One easy way to do this is to type the word “code” followed by a dot “.” at a Command Prompt, Powershell window or Windows Terminal.

Powershell/Terminal Command:

```
code .

```

[![Powershell Command](https://github.com/shahedc/multiweb/raw/main/images/powershell-code-command.PNG)](https://github.com/shahedc/multiweb/blob/main/images/powershell-code-command.PNG)

If you already have VS Code open, use the built-in Terminal (Ctrl+`) to change the current directory to the project root.

In either case, you should end up with VS Code open with the Terminal open in the correction location (project root).

[![VS Code with Terminal panel](https://github.com/shahedc/multiweb/raw/main/images/vscode-terminal.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-terminal.PNG)

## Launch Configuration

This project contains [launch.json](https://github.com/shahedc/multiweb/blob/main/.vscode/launch.json) configuration for a .NET Core console project and a Web API projet.

[![Web API Launch Config](https://github.com/shahedc/multiweb/raw/main/images/launch-json-config-webapi.PNG)](https://github.com/shahedc/multiweb/blob/main/images/launch-json-config-webapi.PNG)<figcaption> Web API Launch Configuration</figcaption>

[![Console Project Launch Config](https://github.com/shahedc/multiweb/raw/main/images/launch-json-config-console.PNG)](https://github.com/shahedc/multiweb/blob/main/images/launch-json-config-console.PNG)<figcaption> Console Project Launch Configuration</figcaption>

## Debug Panel

In the Debug Panel of VS Code, observe that you can see both configurations, ready for launch.

[![Web API in Debug Panel](https://github.com/shahedc/multiweb/raw/main/images/vscode-debug-webapi.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-debug-webapi.PNG)<figcaption> Web API in Debug Panel</figcaption>

[![Console Project in Debug Panel](https://github.com/shahedc/multiweb/raw/main/images/vscode-debug-console.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-debug-console.PNG)<figcaption> Console Project in Debug Panel</figcaption>

## Setting Breakpoints

In the code for each project, set a breakpoint that’s easy to identify.

[![Breakpoint in Web API project](https://github.com/shahedc/multiweb/raw/main/images/vscode-debug-webapi-breakpoint.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-debug-webapi-breakpoint.PNG)<figcaption> Inside Get() method within WeatherForecastController.cs in Web API project </figcaption>

[![Breakpoint in Console project](https://github.com/shahedc/multiweb/raw/main/images/vscode-debug-console-breakpoint.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-debug-console-breakpoint.PNG)<figcaption> Console.WriteLine in Console project  </figcaption>

## Debugging with Breakpoints

From the aforementioned Debug Panel, run the Web API project and then the Console project by clicking the Play/Debug button for each launch configuration.

**Note** : when the web browser launches at the root of the website, you may browse to the WeatherForecast Controller manually, e.g. [https://localhost:5001/WeatherForecast](https://localhost:5001/WeatherForecast)

You should see each program pause at the breakpoints you set earlier.

[![Breakpoint in Web API project](https://github.com/shahedc/multiweb/raw/main/images/vscode-debug-webapi-breakpoint.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-debug-webapi-breakpoint.PNG)<figcaption> Breakpoint in Web API project</figcaption>

[![Breakpoint in Console project](https://github.com/shahedc/multiweb/raw/main/images/vscode-debug-console-breakpoint.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-debug-console-breakpoint.PNG)<figcaption> Breakpoint in Console project</figcaption>

## Continue Running

Press the Play/Continue button to continue running while debugging. Observe the output in a web browser (for the Web API project) or the Terminal within VS Code (for the Web API project)

[![Output in Web API project](https://github.com/shahedc/multiweb/raw/main/images/vscode-debug-webapi-output.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-debug-webapi-output.PNG)<figcaption> Output in Web API project</figcaption>

[![Output in Console project](https://github.com/shahedc/multiweb/raw/main/images/vscode-debug-console-output.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-debug-console-output.PNG)<figcaption> Output in Console project</figcaption>

## Optional: Run Multiple Projects

As a bonus, I have added a Compounds section to the launch.json file.

<pre>
    "compounds": [
        {
            "name": "Both Console & Web API",
            "configurations": [
                ".NET Core Launch (console)",
                ".NET Core Launch (web)"
            ]
        }

</pre>

This will allow you to launch both the Console app (in the Terminal) and the Web API app (in a browser) in rapid succession, with 1 click.

[![Debugging multiple projects](https://github.com/shahedc/multiweb/raw/main/images/vscode-debug-both.PNG)](https://github.com/shahedc/multiweb/blob/main/images/vscode-debug-both.PNG)<figcaption> Debugging multiple projects</figcaption>