How to use the old console app structure in .NET 6.0 console app?

john zyd 421 Reputation points
2021-11-19T20:43:56.837+00:00

Hello:
As I begin to use Visual Studio 2022, I want to port some old code from .NET 5.0 to .NET 6.0 on Windows 10.
However, I found in the new IDE, the old console app structure is gone.
For example, the old console app is something like this:

using System;
namespace ConsoleAppDemo
{
class ConsoleAppDemo
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

But in .NET 6.0, when I created a new Console App project, I see there is only one statement, the others are gone.
Since in my old code (.NET 5.0), I have many methods to call, and many properties to access.
With the old console app structure, it is easy to know where those methods/properties are located, but the new structure, which contains only one statement. Then how I can know where to call/access the methods and/or properties?
Please advise, how I can change the IDE, so I can get the old console app structure back.
Thanks,

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,302 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jaliya Udagedara 2,736 Reputation points MVP
    2021-11-25T22:41:10.26+00:00

    If you want to Use the old program style,

    • Create a new project dotnet new console --framework net5.0
      • Open the project file in a text editor and change <TargetFramework>net5.0</TargetFramework> to <TargetFramework>net6.0</TargetFramework>

    More Information:
    https://learn.microsoft.com/nl-nl/dotnet/core/tutorials/top-level-templates#use-the-old-program-style

    If you prefer to use Visual Studio, Create a new Console Application.

    Choose Target Framework as .NET 5:
    152731-image.png

    And then if you want to use all the nice C# 10 and .NET 6 features, update the csproj file as above.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Karen Payne MVP 35,196 Reputation points
    2021-11-19T22:56:15.797+00:00

    Download the following .zip file (basic console app, .NET Core 5, C#9)

    https://1drv.ms/u/s!AtGAgKKpqdWjkgHTf5WflrRfIZKY?e=S3bWLq

    Copy it to

    C:\Users\TODO\Documents\Visual Studio 2019\Templates\ProjectTemplates

    Open Visual Studio, create a new project, search for Console

    See it, select it

    151123-figure1.png


  2. Bruce (SqlWork.com) 56,926 Reputation points
    2021-11-20T15:29:19.747+00:00

    You can declare a static main, it’s optional. Generally there is little code in the program.cs file, just the startup logic.

    You can add static methods and classes to program.cs, they just go after the startup code.

    0 comments No comments