Dot Net For All

Debug .Net Core project using VS Code on Ubuntu

Hello friends, In this article I will show you how to debug .NET core code project on Linux or Ubuntu using Visual studio code. Once you are done with creating your first .NET core project on Linux, your next requirement would be to debug the code you have written. Because installation and creation of your first project should not be the dead end for you.

Debug .Net Core project using VS Code

Steps to debug .NET Core Core on Linux/Ubuntu

  1. First of all we need code editor to write and debug our code. We will use Visual Studio code and install the same on the Ubuntu machine. The best way to install it is using ubuntu software center as shown in the figure below. Install “Visual Studio Code” and not the “Visual Studio Code – Insiders”.

It may take some time to install Visual studio code in the above step. The next step is to install C# extension for Visual Studio Code by Omni Sharp as shown in the figure below.

Click on the extensions icon on the left hand side panel and search for the C# extension.

The next step is to create a new project. We can use the previous article or you can open the Visual Studio code integrateed terminal to create a new project. Open the terminal under View > Terminal. And type the commands shown in below figure

Open the folder created in above step in the Visual Studio Code.

Create a new file named .vscode/tasks.json. and paste below contents.

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

And finally you have to add the configuration file for the project. You can do this by going to the “Debug” icon present on the left hand side console.

Once you click on the configure button, you will be prompted with the environment. And you have to select “.NET Core Launch (console)”

You can happily debug your code using the green play button present near to the configuration in the above figure.

Conclusion:

I hope this article will help you to debug your code written in C# on Ubuntu platform.

Top career enhancing courses you can't miss

My Learning Resource

Excel your system design interview