File-scoped namespace enabled by default


When creating a new C# class, I would like to have file-scoped namespaced class by default (for proper C# language).

Is that possible in Rider?

Comment actions Permalink


If the project C# language version is >=10.0, the class will be created with file-scoped namespace by default.
Please ensure the setting `File | Settings | Editor | Code Style | C# | Syntax Style | Code body | Namespaces` is set to File-scoped.

The language version is set to 10.0 by default in projects that target .NET6. You can force your project to use the exact language version by editing the .csproj or via `Right-click on project in Solution Explorer | Properties | Application | Language version`.

Sample .csproj with a language version set:

<Project Sdk="Microsoft.NET.Sdk">

Please let me know if it doesn't help or anything is unclear.
Have a nice day!

Comment actions Permalink

Thank you for the help, Dmitry.

I've just found I had a setting overwritten in .editorconfig:

csharp_style_namespace_declarations = block_scoped:silent

I removed that setting and now it works fine. Thank you!

Comment actions Permalink


I am happy to hear that I was able to help you.

Should you have any other questions or difficulties in the future, do not hesitate to contact support.
Have a nice day!


Please sign in to leave a comment.