How To Create a C# 9 Console Application

This post will show you how to create a console application on Linux or Windows machine.

Dotnet

With .NET 5, creating a C# 9 application has gotten easier and simpler and only requires a single command. The following command will create a C# console application called myfirstapp

dotnet new console --name myfirstapp

The output of the command is shown below. If you look closely, you will see that it uses the “Console Application” temple, which is used to create a C# application.

To create an ASP.NET core application we would use the mvc template.

The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on myfirstapp/myfirstapp.csproj...
  Determining projects to restore...
  Restored /home/abbs/myfirstapp/myfirstapp.csproj (in 135 ms).
Restore succeeded.

Once the application has been created, you will see a folder with the following items in it. Program.cs is the actual application. myfirstapp. csproj is the project file for the application.

Program.cs
myfirstapp.csproj
obj

Run

To run the newly created application, I will run the following command from inside the folder (myfirstapp).

dotnet run myfirstapp

The output should look like

Hello World!
Published
Categorized as C#, C# 9

Leave a comment

Your email address will not be published. Required fields are marked *