You can define and maintain a consistent code style in your codebase by defining .NET code style rule options in an EditorConfig
file.
EditorConfig
file to your project.EditorConfig
file take precedence over code styles that are specified in the Options
dialog box.The code style preferences can be set on the Options dialog box from the Tools > Options > Text Editor > [C# or Basic] > Code Style > General.
.editorconfig
file that is associated with the project.Each item in the list shows a preview of the preference when selected.
You can specify the Preference and Severity values using the drop-downs on each line for each code style setting.
The following options are available to set SeverityIf you want to enable Quick Actions for a code style, make sure that the Severity setting is set to other than the Refactoring Only option.
To generate a coding style file, click the Generate .editorconfig file from settings button.
It will generate a coding style .editorconfig
file based on the settings on the Options page.
In Visual Studio 2019, for C# code files you will see a Code Cleanup button at the bottom of the editor.
If a .editorconfig
file exists for the project, those are the settings that take precedence.
With the Code Cleanup broom icon, you can see an expander arrow, let's click that arrow and you will see the following menu.
To configure which code styles you want to apply in one of two profiles in the Configure Code Cleanup dialog box.
After you have configured code cleanup, you can either click on the broom icon or press Ctrl+K, Ctrl+E to run code cleanup to apply code styles from an EditorConfig file or the Code Style options page.