Skip to content

Getting Started with .NET and Visual Studio Code on Ubuntu

Before going through these steps make sure you have done Setup .NET development environment on Ubuntu

Visual Studio Code

Download and install from Visual Studio Code site.

Open Visual Studio Code and press Ctrl + Shift + P. Select Shell Command: Install 'code' command in PATH.

Close Visual Studio Code.

Project Directory

Create a directory called simple in ~/net/simple

mkdir -p ~/net/simple

.NET Project Files

Create the project files:

export PATH="$HOME/.dotnet:$PATH"

cd ~/net/simple

# Switch to use .NET SDK 6.0, 7.0 or 8.0. We do 8.0 here but give the commands for other versions 
# dotnet new globaljson --sdk-version 6.0.417 --roll-forward latestPatch
# dotnet new globaljson --sdk-version 7.0.404 --roll-forward latestPatch
dotnet new globaljson --sdk-version 8.0.100 --roll-forward latestPatch

# create new console application and project
dotnet new console --framework net6.0

# create new solution and add the project to it
dotnet new sln
dotnet sln add simple.csproj

# add .gitignore
dotnet new gitignore

Open the directory in Visual Studio Code:

export PATH="$HOME/.dotnet:$PATH"

cd ~/net/simple
code .

Install the C# Dev Kit extension for Visual Studio Code.

Automate the build

Add the following Visual Studio Code specific files to the .vscode subdir:

.vscode/tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "dotnet",
            "task": "build",
            "group": "build",
            "problemMatcher": [],
            "label": "dotnet: build"
        }
    ]
}

Test the build by pressing Ctrl + Shift + B. Visual Studio Code should execute the build.sh script automatically.

Setup Debugging

Add the following Visual Studio Code specific files to the .vscode subdir:

.vscode/launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "dotnet: build",
            "program": "${workspaceFolder}/bin/Debug/net6.0/simple.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopAtEntry": false
        }
    ]
}

Test the debugging

Set a breakpoint at the Console.WriteLine("Hello, World!"); line in Programs.cs:

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

Press F5 to launch the debugger. It should stop at the breakpoint.