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.in/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 Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

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

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading