You are picking options for the template that creates the project, not project properties. Once the project is created, you need to manually make changes. Say convert back to using Main. note: support for optional top level is a compiler feature, and is based on the format of the file, not project settings.
ASP.Net Core Top-level Statements
I understand what this option does, but I'm wondering if this only applies when you first create a project. I can't find any option to disable top-level statements after the project has been created, and I can't see that VS stores this option. I would assume the most logical place would be in project settings, but I can't find the option.
I did not use this option when I created the project, and I would like to change it, because I find the top-level statements to be very confusing. Do I need to go through and manually edit each file to remove the top-level statements?
Developer technologies ASP.NET ASP.NET Core
-
Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
2024-05-04T16:45:28.81+00:00
1 additional answer
Sort by: Most helpful
-
AgaveJoe 30,126 Reputation points
2024-05-04T11:37:00.4733333+00:00 I can't find any option to disable top-level statements after the project has been created, and I can't see that VS stores this option.
There is nothing to disable. Top level statement is a compiler feature with C# 10. It is totally up to you if you want to use top level statement or not.
https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/top-level-statements
If you are referring to the the implicit using statement then see the following link.
Do I need to go through and manually edit each file to remove the top-level statements?
Yes. As far as I know there is no conversion utility that changes code from a top level style to code blocks with curly brackets, a Program class and Main() method in the project file.