|
1 | 1 | ---
|
2 | 2 | title: Code style options and code cleanup
|
3 | 3 | description: Learn how to configure Visual Studio to apply code style preferences using the Code Cleanup (Visual Studio 2019) and Format Document (Visual Studio 2017) commands.
|
4 |
| -ms.date: 10/03/2024 |
| 4 | +ms.date: 11/11/2024 |
5 | 5 | ms.topic: conceptual
|
6 | 6 | author: mikejo5000
|
7 | 7 | ms.author: mikejo
|
@@ -79,37 +79,54 @@ Starting in Visual Studio 2019 version 16.8, which includes the .NET 5.0 RC2 SDK
|
79 | 79 |
|
80 | 80 | For C# code files, Visual Studio has a **Code Cleanup** button at the bottom of the editor (keyboard: **Ctrl**+**K**, **Ctrl**+**E**) to apply code styles from an EditorConfig file or from the **Code Style** options page. If an *.editorconfig* file exists for the project, those are the settings that take precedence.
|
81 | 81 |
|
82 |
| - |
83 |
| - |
84 | 82 | > [!TIP]
|
85 | 83 | > Rules configured with a severity of **None** don't participate in code cleanup but can be individually applied via the **Quick Actions and Refactorings** menu.
|
86 | 84 |
|
87 |
| -First, configure which code styles you want to apply (in one of two profiles) in the **Configure Code Cleanup** dialog box. To open this dialog box, click the expander arrow next to the code cleanup broom icon and then choose **Configure Code Cleanup**. |
| 85 | +To apply code styles: |
| 86 | + |
| 87 | +1. First, configure which code styles you want to apply (in one of two profiles) in the **Configure Code Cleanup** dialog box. To open this dialog box, click the expander arrow next to the code cleanup broom icon and then choose **Configure Code Cleanup**. |
| 88 | + |
| 89 | +  |
| 90 | + |
| 91 | +1. After you've configured code cleanup, use one of the following methods to run code cleanup: |
| 92 | + |
| 93 | + - Click on the broom icon or press **Ctrl**+**K**, **Ctrl**+**E** to run code cleanup. |
88 | 94 |
|
89 |
| - |
| 95 | +  |
90 | 96 |
|
91 |
| -After you've configured code cleanup, you can either click on the broom icon or press **Ctrl**+**K**, **Ctrl**+**E** to run code cleanup. You can also run code cleanup across your entire project or solution. Right-click on the project or solution name in **Solution Explorer**, select **Analyze and Code Cleanup**, and then select **Run Code Cleanup**. |
| 97 | + - To run code cleanup across your entire project or solution, right-click on the project or solution name in **Solution Explorer**, select **Analyze and Code Cleanup**, and then select **Run Code Cleanup**. |
92 | 98 |
|
93 |
| - |
| 99 | +  |
94 | 100 |
|
| 101 | + If you want your code style settings to be applied every time you save a file, you may like the [Code Cleanup on Save](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.CodeCleanupOnSave) extension. |
95 | 102 | ::: moniker-end
|
96 | 103 |
|
97 | 104 | ::: moniker range=">=vs-2022"
|
98 | 105 |
|
99 | 106 | For C# code files, Visual Studio has a **Code Cleanup** button at the bottom of the editor (keyboard: **Ctrl**+**K**, **Ctrl**+**E**) to apply code styles from an EditorConfig file or from the **Code Style** options page. If an *.editorconfig* file exists for the project, those are the settings that take precedence.
|
100 | 107 |
|
101 |
| - |
102 |
| - |
103 | 108 | > [!TIP]
|
104 | 109 | > Rules configured with a severity of **None** don't participate in code cleanup but can be individually applied via the **Quick Actions and Refactorings** menu.
|
105 | 110 |
|
106 |
| -First, configure which code styles you want to apply (in one of two profiles) in the **Configure Code Cleanup** dialog box. To open this dialog box, click the expander arrow next to the code cleanup broom icon and then choose **Configure Code Cleanup**. |
| 111 | +To apply code styles: |
| 112 | + |
| 113 | +1. First, configure which code styles you want to apply (in one of two profiles) in the **Configure Code Cleanup** dialog box. To open this dialog box, click the expander arrow next to the code cleanup broom icon and then choose **Configure Code Cleanup**. |
| 114 | + |
| 115 | +  |
| 116 | + |
| 117 | +1. After you've configured code cleanup, use one of the following methods to run code cleanup: |
107 | 118 |
|
108 |
| - |
| 119 | + - Click on the broom icon or press **Ctrl**+**K**, **Ctrl**+**E**. |
109 | 120 |
|
110 |
| -After you've configured code cleanup, you can either click on the broom icon or press **Ctrl**+**K**, **Ctrl**+**E** to run code cleanup. You can also run code cleanup across your entire project or solution. Right-click on the project or solution name in **Solution Explorer**, select **Analyze and Code Cleanup**, and then select **Run Code Cleanup**. |
| 121 | +  |
111 | 122 |
|
112 |
| - |
| 123 | + - To run code cleanup across your entire project or solution, right-click on the project or solution name in **Solution Explorer**, select **Analyze and Code Cleanup**, and then select **Run Code Cleanup**. |
| 124 | + |
| 125 | +  |
| 126 | + |
| 127 | + If you want your code style settings to be applied every time you save a file, go to **Options** > **Text Editor** > **Code Cleanup** and select **Run Code Cleanup profile on save**. |
| 128 | + |
| 129 | +::: moniker-end |
113 | 130 |
|
114 | 131 | ## Code cleanup settings
|
115 | 132 |
|
@@ -163,13 +180,6 @@ Most of the code cleanup settings map to one or more .NET code styles supported
|
163 | 180 |
|
164 | 181 | ::: moniker-end
|
165 | 182 |
|
166 |
| -::: moniker range=">=vs-2022" |
167 |
| -If you want your code style settings to be applied every time you save a file, go to **Options** > **Text Editor** > **Code Cleanup** and select **Run Code Cleanup profile on save**. |
168 |
| -::: moniker-end |
169 |
| -::: moniker range="<=vs-2019" |
170 |
| -If you want your code style settings to be applied every time you save a file, you may like the [Code Cleanup on Save](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.CodeCleanupOnSave) extension. |
171 |
| -::: moniker-end |
172 |
| - |
173 | 183 | ## Related content
|
174 | 184 |
|
175 | 185 | - [Quick Actions](../ide/quick-actions.md)
|
|
0 commit comments