In .NET 6.0, the Main
method is simplified by removing and main method. Now it’s possible to start writing code directly without it.
But I want to enable it back and don’t want to write it by hand every time when new project is created. I’m using VS Code, but I couldn’t find any straight way to accomplish this.
Is there any option for this or any shortcut like writing "prop" to create property quickly.
2
Answers
With your cursor on the code that it starts with, you can press Ctrl+., and click "Convert to ‘Program.Main’ style program"
When creating a console application project on the command line, there are options you can specify. By default:
Will create a console application in the "newer" (as of .NET 6) style of allowing top-level statements. You can suppress this on the command line when creating the project:
This would create the project with an explicit class and method entry point.