Yes, the setup of .editorconfig
files is hierarchical, where settings in child .editorconfig
files add to or override those in parent .editorconfig
files.
It is even possible to stop the inheritance starting from a certain level in a child folder by including root = true
in that child .editorconfig
file.
From the documentation
When you add an .editorconfig
file to a folder in your file hierarchy, its settings apply to all applicable files at that level and below.
To override some or all of the EditorConfig settings, add an .editorconfig
file at the level of the file hierarchy you want those overridden settings to apply. The new EditorConfig file settings apply to files at the same level and any subdirectories.
If you want to override some, but not all of the settings, specify just those settings in the .editorconfig
file. Only those properties that you explicitly list in the lower-level file are overridden. Other settings from higher-level .editorconfig
files continue to apply.
Such a folder and files hierarchy might look like below.
\ YourSolution
- YourSolution.sln
- .editorconfig
...
\ Src
\ Project1
...
\ Project2
...
\ Project3
- .editorconfig
...
\ Tests
- .editorconfig
\ Tests1
...
\ Tests2
- .editorconfig
The root .editorconfig
file can also be in a common parent folder for all your Visual Studio solutions.
\ YourSolutions
- .editorconfig
\ YourSolution1
- YourSolution1.sln
...
\ YourSolution2
- YourSolution2.sln
...
Example files.
Root .editorconfig
file
[*.cs]
dotnet_sort_system_directives_first = true
dotnet_style_require_accessibility_modifiers =
for_non_interface_members:error
Child folder .editorconfig
file
[*.cs]
dotnet_sort_system_directives_first = false
dotnet_style_require_accessibility_modifiers =
for_non_interface_members:silent
In VS2022 17.4.3+, when dealing with multiple .editorconfigs you may need to use a standard text editor instead of the default .editorconfig gui tool.