editorconfig rule to enforce that namespace is set in all c# files
04:28 21 Nov 2025

I want to set a rule in .editorconfig so that all C# files where namespace is not explicitly set should render an error.

I've added these:

  • dotnet_diagnostic.IDE0130.severity = error # Namespace does not match folder structure
  • dotnet_diagnostic.IDE0161.severity = error # Namespace declaration preferences (prefer file-scoped)
  • csharp_style_namespace_declarations = file_scoped:error

Namespace is validated to follow file structure. Screenshot IDE0130

And to be file scoped Screenshot IDE0161

But if I remove the namespace altogether, I get no validation error.

c# .net editorconfig