How to get back the old Console Project in .NET 6

Since .NET 6, Microsoft has changed the template for the console project.

From now on, the console template will use top-level statements. Using new features like global usings and file-scoped namespaces, .NET allows you to write the code statements directly without boilerplate code.

Most programmers hate this new project style that removes the Main method and the default using statements. I include myself in this category, and I want my old template back, so I have searched for options.

Target .NET 5 framework instead of .NET 6

The easiest option is to choose .NET 5 target framework when you create a new project. Then you edit the project file and switch back to .NET 6.

Console Project - choosing the target framework

After you create the project, you can edit your csproj file and switch back to .NET 6:

<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Copy the old template from the documentation

Another option is to just copy the old template from the documentation:

using System;

namespace Application
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Install Classic Console Template

Visual Studio allows you to create and install templates.

There is a template called Classic Console Template that allows you to create an old console project that targets .NET 6. This is by far the cleanest option.

Leave a Comment