When creating a new project in VS 2022 with .NET 6, following new features are added automatically:
Is there a way to create a .NET 6 project
without top-level-statements (a workaround other than creating a .NET 5 project & changing project type to .NET 6)
with implicit usings & nullable references disabled (without editing the project file each time after project creation)
I suggest keeping nullable reference types on. I'd echo Embracing nullable reference types and say that all new code should use it. Here's the original statement:
When .NET 5 rolls around, if we feel the nullable rollout phase has been a success, I could see us turning the feature on by default for new projects in Visual Studio. If the ecosystem is ready for it, there is no reason why any new code should ignore the improved safety and reliability you get from nullability annotations!
VS2022 17.3.0 (Preview 1.1) supports disabling top-level statements when creating console apps:

Targetting the .net5 framework and editing the project file is the official way to use the old program style.
Please see Use the old program style.
While a .NET 6 console app template generates the new style of top-level statements programs, using .NET 5 doesn't. By creating a .NET 5 project, you'll receive the old program style. Then, you can edit the project file to target .NET 6 but retain the old program style for the Program.cs file.
and
The features that make the new program simpler are top-level statements, global using directives, and implicit using directives.
BTW. Cast your vote on the official Should the console project template use top-level statements directly in gihub:

I came to this post to see if it would still be possible to have the Main() method when creating projects via command prompt. Looks like there is! as of .NET 6.0 SDK one can add the --use-program-main command line option when creating new projects as follows:
dotnet new console --use-program-main
Source: Use the old program style
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With