Create Your First C# Project with Visual Studio, VS Code, Rider, and dotnet CLI

13 minutes

Table of Contents

In this article we will guide you in creating your first C# project using three IDEs, Visual Studio, Visual Studio Code, and Rider. We will round out the article by also showing you using dotnet CLI tool.

Before you start

In our previous article on introducing and installing .NET, we have a section on Verifying your .NET installation. If you already know you have .NET installed, please continue. If you are unsure, use the previous article to ensure you have .NET installed, and you will be ready to go.

Do you have an Integrated Development Environment (IDE) installed?

Below are instructions on how to install Visual Studio, Visual Studio Code, JetBrains Rider IDEs, and also how to configure them to develop for C#.

If you do not have an IDE to develop C# in, please choose one of those listed below and install using the guide in the relevant tab.

Install and configure Visual Studio for C# development on Windows

Head over to the Visual Studio download page in your favourite internet browser.

Choose the Free download button and download Visual Studio Community Edition.

A screenshot of the Visual Studio download page

Open the downloaded installer, and on the workloads selection screen choose the following and tap the Install button.

  • ASP.NET and web development
  • Azure development
  • .NET Multi-platform App UI development
  • .NET desktop development
A screenshot of the Visual Studio installer workloads selection screen

If you wish to launch Visual Studio immediately after the installation has finished, keep the Start after installation checkbox ticked.

A screenshot of the Visual Studio install progress screen

If the Start after installation was not ticked, when the installation has finished, tap the Launch button to open Visual Studio.

A screenshot of the Visual Studio installer with Visual Studio installed

Installation completed

Visual Studio on Windows is now installed and you are ready to develop C#!


Create your first Hello, World! project in C#

Now that you have your device set up to develop C#, let us continue and create your first C# project.

Below are instructions on how to create your first C# project in the dotnet CLI tool, Visual Studio, Visual Studio Code, and JetBrains Rider

Create your first C# project using the dotnet CLI

Below are instructions on how to create your first C# project using the dotnet CLI tool.

A screenshot of a terminal showing the command to create a C# console project

Open your terminal of choice and navigate to a directory where you wish to store your C# project.

Type in the following command:

dotnet new console --name HelloWorld

The dotnet CLI too has a plethora of commands. The new command takes a template name, and in this case we are creating a project based on the console application template.

Furthermore, we would like to choose the name of our project so passing the -name argument will allow us to specify the name that we wish the project to be. You have the option of shortening the argument to -n, although we prefer to be explicit in what we are doing, at least if we are automating these commands.

A screenshot of a terminal showing changing directory to a our newly created hello world C# project

Now let's navigate to our newly created HelloWorld project using the following command:

cd HelloWorld

Running your first C# project using the dotnet CLI

A screenshot of a terminal showing running our newly created hello world C# project

To ensure the project is set up correctly, input the following command to run the project:

dotnet run

If the terminal displays Hello, World! as the output of running the project, it has been set up correctly.

Congratulations! you have set up and ran your first C# project in the dotnet CLI tool.


Understanding your first C# project code

Now that we have a new project in C#, let us describe line by line what it does. Note though, that the code snippets below were from a project created using the dotnet CLI tool.

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

In the first article of this series, Introduction to C#: A Beginner's Guide we mentioned top-level statements. You can see in the example on that article that you can simplify your program by eliminating all of the boilerplate code such as defining the Program class, and the Main method.

In the project we created in this article, it means your top-level Program.cs file contains only the code you actually want to work with.

Additionally, the default for new projects in .NET is to use top-level statements. This can be turned off when using the various IDEs in the new project wizard, or by adding the --use-program-main argument when using the dotnet CLI tool, as shown in the example below.

dotnet new console --use-program-main --name HelloWorld

Breakdown of the Program.cs file

Here we can see on the first line of the file a comment. Comments in C# are to provide context to sections of code, be it classes, records, structs, methods, properties, fields, etc. We will go through comments further in a future article. For now, just know that comments are not executed as code within a C# program.

In this case, the comment is pointing you to a website which will describe the console template in detail.

// See https://aka.ms/new-console-template for more information

Secondly we have the WriteLine method, in the Console class. For now, think of Console as a container of methods to manipulating the terminal/console that you will see when you run the program.

The WriteLine method specfically outputs some text to the console/terminal, in this case, the words Hello, World!. We can explain more features of the Console class in a future article.

Console.WriteLine("Hello, World!");

In conclusion

Now that you have set up your environment for C# development and created your first C# HelloWorld project, you are well on your way to becoming a C# developer. Congratulations!

Thank you for taking the time to read this guide, and please check back often for more C# and .NET articles.


Filed under Fundamentals, and tagged under Core Concepts , dotnet CLI , JetBrains Rider , Visual Studio , Visual Studio Code

View the source code for this article on GitHub