DEV Community

Chris Achinga
Chris Achinga

Posted on • Originally published at chrisdevcode.hashnode.dev on

C#(Dotnet) Setup in Ubuntu with VSCode

C# is a general-purpose, multi-paradigm programming language encompassing static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented, and component-oriented programming disciplines.

In this article, I will take you through installing and setting up C#(c-sharp) environment on a Ubuntu OS(Operating System).

Requirements:

Note that .NET is a C# library

Installing .NET (Csharp)

Start your terminal on Ubuntu;

ctr + shift + T

Terminal

First we need to add the Microsoft package signing key to your list of trusted keys and add the package repository. Run the commands in the order as they appear;

wget https://packages.microsoft.com/config/ubuntu/21.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb


sudo dpkg -i packages-microsoft-prod.deb

Enter fullscreen mode Exit fullscreen mode

Installing .NET SDK

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-5.0

Enter fullscreen mode Exit fullscreen mode

Installing The Runtime

sudo apt-get update; \
  sudo apt-get install -y apt-transport-https && \
  sudo apt-get update && \
  sudo apt-get install -y aspnetcore-runtime-5.0

Enter fullscreen mode Exit fullscreen mode

To test the installation, run the command dotnet on your terminal;

dotnet

Enter fullscreen mode Exit fullscreen mode

test.png

yaay! we are done with that.

https://docs.microsoft.com/en-us/dotnet/core/install/linux-ubuntu

https://dotnet.microsoft.com/download

Visual Studio Code Setup

This is an easy procedure, as we only need to install an extension on VSCode.

The extension is: C# for Visual Studio Code (powered by OmniSharp)

https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp

extension screenshot

How to Install VSCode Extensions:

https://youtu.be/SKcZ3cwX8lA

Once you have the extension added, we can create the famous Hello World application in C#.

Creating Hello World in C

First you create a new Project folder, say c-sharp, and open the empty folder with Visual Studio Code.

Open the integrated terminal in VSCode or use the terminal (ensure you are in the project's folder path).

To start a C# program use the command below;

dotnet new console

Enter fullscreen mode Exit fullscreen mode

dotnet new is creating a new dotnet project. console is to specify the application type, in this case our program will be running on our terminal (console).

Once you run the command, a couple of files and folders are created.

We are only interested in the Program.cs file for now:

using System;

namespace hello
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

You don't need to change anything for now.

Let's run the program using the command:

dotnet run

Enter fullscreen mode Exit fullscreen mode

hello.png

And that is how you get to use C# in Ubuntu.

Demo Files:

https://github.com/ChrisAchinga/c-sharp

Don't mind my terminal name, my laptop is really slow LOL!

Top comments (0)