Ubuntu : Running .NET Core console application

Executing .NET core console application on LINUX
Executing .NET core console application on LINUX

Hi All,

Greetings for the day 🙂 LIFE IS BEAUTIFUL 🙂

Today something new 🙂 Running .NET core HelloWorld console application on Ubuntu box

Background / Details :

  • Here, we might have a questions what is the need to execute the .NET core application on Ubuntu
  • I am studying / understanding DOCKER and KUBERNAETES for this I need to create docker image from scratch and trying simple application and this is the first step

STEP 1 : First step is to install dotnet core on our LINUX / UBUNTU box

  • I have created UBUNTU vm on my free subscribed AZURE
  • We could verify if dotnet is installed or not by executing command dotnet
dotnet

Fig: Running .NET Core console application – verifying if DOTNET is installed or not
  • If dotnet is not installed then we get the below message as shown in above Fig

Command ‘dotnet’ not found, but can be installed with:

sudo snap install dotnet-sdk

  • Lets install the dotnet as shown in below steps
Fig: Running .NET Core console application
Fig: Running .NET Core console application
  • Once DOTNET installed successfully, we will get success message as shown in below fig
Fig: Running .NET Core console application

STEP 2 : Creating simple “Hello World” .NET core console application

  • To create console application having name – “KnowledgeJunction.NetCore.Docker”, we will execute the command
dotnet new console -o App -n KnowledgeJunction.NetCore.Docker

Fig: Running .NET Core console application – Creating DOTNET core console application
Fig: Running .NET Core console application – App folder in which our console application solution structure will be created
  • We have solution structure as in App folder as shown in below Fig with following files
    • KnowledgeJunction.NetCore.Docker.csproj
    • Program.cs
Fig: Running .NET Core console application – Solution contains .CSPROJ and Program.cs files
  • Open the “Program.cs” file in Terminal
Fig: Running .NET Core console application – Program.cs file

Step 3 : Build and Run the application – Next step is build and run our applicationlets see the output

  • To build our appliaction we will execute dotnet command with build option as
dotnet build

Fig: Running .NET Core console application – Building our aplication using – dotnet build
  • This is the simple console application so its ok to open files in Terminal
  • But for our large applications / solutions I will go for Visual Studio Code. I have installed the Visual Studio Code We have detailed article for installing Visual Studio Code on LINUX boxLinux / Ubuntu : Installing Visual Studio Code
  • Once we have Visual Studio Code, I have also installed C# extention for Visual Studio Code
  • Open the our project folder in Visual Studio Code as shown in below Fig
  • From “Visual Studio Code” terminal we will build and run our application
  • On successful build we could run our application to have output
dotnet run

Fig: Running .NET Core console application – Opened our project folder in “Visual Studio Code”

We have very good series of articles on Ubuntu / Linux – https://knowledge-junction.com/category/technology-articles/linux/

Thanks for reading 🙂 HAVE A SAFE LIFE 🙂 TAKE CARE 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL :) ENJOY THE WHOLE JOURNEY :) Founder of Knowledge Junction and live-beautiful-life.com, Author, Learner, Passionate Techie, avid reader. Certified Professional Workshop Facilitator / Public Speaker. Scrum Foundation Professional certificated. Motivational, Behavioral , Technical speaker. Speaks in various events including SharePoint Saturdays, Boot camps, Collages / Schools, local chapter. Can reach me for Microsoft 365, Azure, DevOps, SharePoint, Teams, Power Platform, JavaScript.

You may also like...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: