Skip to content
.NET Studies

Creating a console project

What is a console project

Console projects are simple .NET projects used to create examples or small pieces of code to validate some piece of information or need.

We can create as many console projects as we like, and they are quite simple. I will explain each file and what it is for.

Creating a console project using the .NET CLI

If you have the .NET compiler installed on your computer, you can create a project straight from your console. First, check which version of .NET you have installed.

Checking the .NET version in the terminal
dotnet --version

Now we can create an initial project template with the following command, and I will show the generated files:

Creating a console project called MyApp
dotnet new console -n MyApp

When we run this command, it creates the following files in a directory:

  • DirectoryMyApp/
    • MyApp.csproj
    • Program.cs
    • appsettings.Development.json
    • appsettings.json

A short description of each file:

  • MyApp.csproj
    • XML file
    • Defines which files are part of the build
    • Manages dependencies (NuGet packages, references, etc.)
    • Configures the build (.NET version, output type, etc.)
    • Integrates with tools (dotnet CLI)
    • NOTE: without this file, .NET would not know how to build or run the project.
  • Program.cs
    • C# file with the startup code of our project, including Main().
    • This is the entry point for our project’s configuration. We can create multiple C# files with whatever we need and connect them in this file so they start when the project starts.
  • appsettings.json
    • A JSON file holding the necessary settings in a structured way.
    • Used for RabbitMQ settings, logs, database connections, etc.
    • Contains all the settings needed for external projects or programs the application depends on.

Creating a console project with Visual Studio 2022

Visual Studio 2022 start page

When you open Visual Studio 2022, it shows the most recently opened projects.

On the same page there is the Create new project option, which takes us through a set of pages to create our project.

Visual Studio main page

List of project types

Visual Studio 2022 shows a list of the project types we can create.

In this case we must choose the Console App option and click Next to go to the following steps

List of project options

Define the project name and Solution name

A Solution is a file that manages all connected projects. We use this file, with the .sln extension, to define how multiple projects are managed together. I will explain this file later, both in the console and in Visual Studio 2022.

Now let’s define the name of our console project; the solution file will get the same name.

Project name definition

Defining the project version

Now we simply choose which version of .NET we want to use. In my case I use .NET 8.

Define .net version

After creation in Visual Studio 2022

When created through Visual Studio, our project is opened through the Solution, so the .csproj file is not shown: it was read and is displayed in our IDE by the Solution Explorer under the project name.

Solution Explorer

If we click on the name MyApp, it shows the contents of the MyApp.csproj file, which holds the configuration and the NuGet dependencies of the project.

csproj into visual studio

If we click on Program.cs, we see the basic code automatically generated by Visual Studio so we can test the project build.

Program in Visual Studio

In the next step, I will show how to set up a solution and test projects.