How to program in C# in Linux (.Net Core & ASP .Net Core without Mono)

Jesus Alvarado
5 min readOct 29, 2020

What would you think if I tell you, you can program in .Net 3.1 and ASP Net in Linux with the Microsoft .Net SDK?, Well today it’s a reality and .Net 5 is coming soon (in fact you can test the preview version).

In the past months, Microsoft surprises us with more and more Microsoft Software that can run natively on Linux, in this post, I am going to teach you how to install the Microsoft .Net SDK on Linux and also how to create your first program using this SDK.

  1. Supported Linux distributions
  2. Install the .Net Code SDK & .Net runtime
  3. Configure VS Code
  4. Hello .Net Core (Your first App)

1. Supported Linux distributions

Before start whit this journey, you must know if your actual OS is supported because not all the versions are supported.
Then let’s review the Linux distributions and versions supported for .Net 3.1.x.

  • Alpine 3.9 + (Yhea! it’s docker time)
  • CentOS 7
  • CentOS 8
  • Debian 9
  • Debian 10
  • Fedora 31
  • Fedora 32
  • OpenSUSE 15
  • RHEL 7
  • RHEL 8
  • SLES 12 SP2
  • SLES 15
  • Ubuntu 16.04 LTS
  • Ubuntu 18.04 LTS
  • Ubuntu 20.04 LTS

I don’t want to extend this too much because if you are like me, you are anxious to programming, so I will provide you the simplified installation process for some of the more used OS.

2. Install .Net Core SDK & .Net Runtime

Install .Net Core on Ubuntu 20.04

# Get the repowget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.debsudo dpkg -i packages-microsoft-prod.deb# Install apt-transport
sudo apt-get install -y apt-transport-https
# Update your repo
sudo apt-get update
# Install the SDK
sudo apt-get install -y dotnet-sdk-3.1
# Install the full runtime
sudo apt-get install -y aspnetcore-runtime-3.1
# Install only the .Net Core runtime
sudo apt-get install -y aspnetcore-runtime-3.1

Install .Net Core on Debian 10

# Get the repowget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.debsudo dpkg -i packages-microsoft-prod.deb# Install apt-transport
sudo apt-get install -y apt-transport-https
# Update your repo
sudo apt-get update
# Install the SDK
sudo apt-get install -y dotnet-sdk-3.1
# Install the full runtime
sudo apt-get install -y aspnetcore-runtime-3.1
# Install only the .Net Core runtime
sudo apt-get install -y aspnetcore-runtime-3.1

Install .Net Core on CentOS 7

# Get the repo
sudo rpm -Uvh https://packages.microsoft.com/config/centos
/7/packages-microsoft-prod.rpm
# Install the SDK
sudo yum install dotnet-sdk-3.1
# Install the full runtime
sudo yum install aspnetcore-runtime-3.1
# Install only the .Net Core runtime
sudo yum install dotnet-runtime-3.1

Install .Net Core on CentOS 8

# Install the SDK
sudo dnf install dotnet-sdk-3.1
# Install the full runtime
sudo dnf install aspnetcore-runtime-3.1
# Install only the .Net Core runtime
sudo dnf install dotnet-runtime-3.1

Install .Net Code on Fedora 32

# Install the SDK
sudo dnf install dotnet-sdk-3.1
# Install the full runtime
sudo dnf install aspnetcore-runtime-3.1
#Installonly the .Net Core runtime
sudo dnf install dotnet-runtime-3.1

3. Configure VS Code

Get the C# extension

Install it without leaving the Bash

code --install-extension ms-dotnettools.csharp

Or you can go her:

Configure VS Code

You can modify your settings.json or simply use a workspace configuration if you want, this is my VS Code settings.json and workspace file, use them if you want (If you have a good idea to expand this configuration let me know it).

4. Hello .Net Core

I will use VS Code because it is free and accessible for all, to start with the funny part, create a folder where you will store all your code, some thing like ~/Projects/dotNet/Hello-dotNet and then “vscode it”

# Lazy snnipet
mkdir -vp ~/Projects/dotNet/Hello-dotNet \
cd ~/Projects/dotNet/Hello-dotNet \
code

Create a VS Code Workspace (it is a good practice and you can manage specific configurations for your project that you can share later)

Create a VS Code workspace

(optional) Configure the workspace file as you prefer, this is my personal configuration and you can use it if you want.

Create your project executing the following command in your project’s root folder

dotnet new console
Create a .Net Core project

With this command you can create all the base project structure, feel free to inspect all this files.

Your project structure

Open the Program.cs and let VS Code install some thing it need to work with the .Net SDK, it will take a twice minutes according with your Internet connection speed

As you can see, you have an “Hello World!” ready to work, now test your installation running this code using the command dotnet run in the VS Code terminal or in bash

Run your code!

Now you are ready to code in C# with the Microsoft .Net Core SDK, put this code in a Docker with .Net Runtime and conquest the world with your code.

This is all for this now, I really appreciate your time. Stay connected for the next part

It it was useful for you, let me know it whit your claps ;)

If this article has been useful to you, I invite you to follow me on my social networks to find out about my publications (English and Spanish):

Medium: https://medium.com/@jesus.alvb
Twitter: @JesusAlvB
Facebook: https://fb.me/JesusAlvaradoBastida
Printerest: https://www.pinterest.com.mx/JesusAlvaradoB

--

--