Open vsfeedback opened 8 months ago
This was discussed at the time, and .net didn't want this as it would mean users without any sort of config set would now see new files generated with FSNS where the rest of their files are block-scoped.
What might make sense is that we might want to look at sibling files in the same project and see what they do and follow that.
This issue has been moved from a ticket on Developer Community.
Repro steps:
Result: The created project uses the older style blocked scoped namespaces instead of the file scoped namespaces added in C# 10
Most of the templates (at least .NET MAUI) use file scoped namespaces in the template and you get that when creating the project via the CLI or VS Code. However, when creating the project in VS Windows it reformats the created files, so it switches back to block namespaces
Expected: So this isn't a bug per se, but it's not really the experience we want for new users. It would be better (arguably) if the global VS default settings were updated to use file scoped namespaces. That way new users would see it for new projects they create and item templates they add.
For other code style preferences this is less of an issue - as users add code to a new project they choose what style to use for that code and may eventually add their own .editorconfig. But the namespace is there by default in many of the .NET templates (both project and item templates); it's not user written code, so it ideally should be modern out of the box.
Even newer templates (e.g. console) use top level statements by default if there's just a single Program.cs source file in the template. But for templates that have multiple C# source files (e.g. MAUI) or don't have a Program.cs (e.g. class library), the change above would also them to use the more modern language feature of file scoped namespaces to reduce indent levels.
Original Comments
Feedback Bot on 3/1/2024, 00:14 AM:
(private comment, text removed)
Original Solutions
(no solutions)