Code style preferences
Code style preferences can be set for your C# and Visual Basic projects by opening the Options dialog box from the Tools menu. In the Options dialog box, select Text Editor > [C# or Basic] > Code Style > General. Options set in this window are applicable to the local machine only.
Each item in the list shows a preview of the preference when selected:
This topic applies to Visual Studio on Windows. For Visual Studio for Mac, see Editor behavior in Visual Studio for Mac.
Preference and severity
For each item, you can set the Preference and Severity values using the drop-downs on each line. Severity can be set to None, Suggestion, Warning, or Error. If you want to enable Quick Actions for a code style, ensure that the Severity setting is set to something other than None. The Quick Actions light bulb icon appears when a non-preferred style is used, and you can choose an option on the Quick Actions list to automatically rewrite code to the preferred style.
Code style settings for .NET can also be managed with an EditorConfig file. Settings in the EditorConfig file take precedence over options selected in the Options dialog box. You can use an EditorConfig file to enforce and configure the coding style for your entire repo or project.
Format Document command
In Visual Studio 2017 version 15.8 and later, you can configure the Format Document command (Edit > Advanced > Format Document) to perform additional code cleanup on a file, such as remove and sort usings or apply code-style preferences. You can define which settings you want Format Document to apply on the Formatting options page.
Code cleanup respects settings configured in an .editorconfig file, or lacking that rule or file, those set in Tools > Options > Text Editor > C# > [Code Style or Formatting].
The first time you trigger the Format Document command in Visual Studio 2017, a yellow info bar prompts you to configure your code cleanup settings.
Rules configured as none in an .editorconfig file don't participate in code cleanup, but can be individually applied via the Quick Actions and Refactorings menu.