Post

C# development environment in Visual Studio Code on Ubuntu

C# software can be developed in Visual Studio on Windows in general. However, it can also be developed in Ubuntu environments. A well-known IDE is MonoDevelop provided by the Mono project. However, let’s create a VS Code C# software development environment that uses more than this. Based on Ubuntu 20.04.

Install .NET family

First, we will add a repository that contains .net. And we will install the three below, and the other three were installed together just by installing the .NET SDK. Please look at the other two for confirmation purposes.

  • .NET SDK
  • .NET Core
  • ASP.NET Core
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cd ~/
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb;rm packages-microsoft-prod.deb

sudo apt update

# .NET SDK
sudo apt install -y dotnet-sdk-6.0

# .NET Core
sudo apt install -y dotnet-runtime-6.0

# ASP.NET Core
sudo apt install -y aspnetcore-runtime-6.0

Let’s check if you’ve installed all of them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.413
 Commit:    10710f7d8e

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /usr/share/dotnet/sdk/6.0.413/

global.json file:
  Not found

Host:
  Version:      6.0.21
  Architecture: x64
  Commit:       e40b3abf1b

.NET SDKs installed:
  6.0.413 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.21 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.21 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Download .NET:
  https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info
  

C# Development Environment On VS Code

Search for c# as a keyword, and install C# Dev Kit including others.

ExtensionCommentReference
C# Dev KitC# Basic environment for developmenthttps://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit
Visual NugetManaging Nuggets Packageshttps://marketplace.visualstudio.com/items?itemName=FullStackSpider.visual-nuget

By installing the C# Dev Kit extension, you can create a basic development environment needed for C# development.

Visual Studio Code - Extension - `C# Dev Kit` Visual Studio Code - Extension - C# Dev Kit

The Visual NuGet extension brings the Nuget Package GUI experience of the Windows Visual Studio IDE to VS Code.

When you right-click on the project file (.csproj), you can find Visual Nuget: Manage Packages.

Visual Studio Code - Extension - `Visual Nuget` Visual Studio Code - Extension - Visual Nuget

Hello World Sample Project

Open View > Terminal. And create my project folder and create console projects.

1
2
3
4
mkdir <my workspace>/my_csharp
cd <my workspace>/my_csharp
dotnet new console

Write the contents of Program.cs based on the template below.

https://learn.microsoft.com/ko-kr/dotnet/core/tutorials/top-level-templates

1
2
3
4
5
6
7
8
9
10
11
12
using System;  

namespace MyApp // Note: actual namespace depends on the project name.
{
    internal class Program
    {    
        static void Main(string[] args)    
        {        
            Console.WriteLine("Hello World!");        
        }
    }
}

Generate Assets for Build and Debug

You can create an Asset from Command Palette....

In other words, This creates a build environment such as basic Assets such as solution (.sln) files.

Visual Studio Code - Command Palette...(Ctrl + Shift + P) - .NET: Generate Assets for build and Debug Visual Studio Code - Command Palette…(Ctrl + Shift + P) - .NET: Generate Assets for build and Debug

Shortcut keys in VS Code

ShortcutsContents
Ctrl + Shift + BBuild
F5Start Debugging
Ctrl + .Quick Actions and Refactorings
Ctrl + Shift + -Go Forward
Ctrl + Alt + -Go Back

This post is licensed under CC BY 4.0 by the author.