Starting from VS2022-Preview2, there is no need to additional extension to "format on-save", you just run a customized code cleanup that contains "Format document" action on-save:

  1. Customize your cleanup profile to perform "Format document" action (if not already there), in Analyze > Code Cleanup > Configure Code Cleanup
  2. Enable "Run code cleanup profile on save" in VS configuration Tools > Options > Text Editor > Code Cleanup

Bringing Code Cleanup on Save To Visual Studio 2022 17.1 Preview 2

Unfortunately code cleanup setting is not included to .editorconfig file neither to exported config file .vssettings that could be shared across a team, maybe it will be included in the future.

Some feature requests related to this:

  • visual studio 2019 allow import and export Configure Code Cleanup profile

  • Provide a way to share Code Cleanup profiles as related to EditorConfig

  • Code Cleanup and EditorConfig

Answer from Cfun on Stack Overflow
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
Code Formatter - Visual Studio Marketplace
Extension for Visual Studio - Format the class file and arrange fields, properties and methods as per StyleCop. Features: Format the class file (.cs) to arrange members of class in the proper order. Using statements are brought inside namespace block. Unwanted namespaces are removed.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ visualstudio โ€บ ide โ€บ code-styles-and-code-cleanup
Code Style Options and Code Cleanup - Visual Studio (Windows) | Microsoft Learn
For formatting styles, select options under Formatting. For code style preferences associated with Quick Actions and IDE code style rules, select options under General or Naming. Each item in the list shows a preview of the preference when you ...
๐ŸŒ
Reddit
reddit.com โ€บ r/visualstudio โ€บ why is code formatting such a struggle in visual studio?
r/VisualStudio on Reddit: Why is code formatting such a struggle in Visual Studio?
March 29, 2025 -

Hi everyone,

I'm really struggling to have proper code formatting in my Visual studio 2022 and would love to hear your guys advice, tricks or experiences:

Let me start with what options I'm aware of:

1. Tools -> options -> C# -> Code Style -> Formatting
I like this option but it simply does not cover all scenarios I want formatted. For example removing white lines in my methods. This is an option that seems so obvious but there is not a checkmark to configure it (as far as I can see).

2. Shortcuts: Tools -> options -> Environment -> Keyboard -> EditFormatDocument
This is great that I'm able to have a shortcut, I have it on visual studio 6 as mapping scheme. But I found that it doesn't always work and for example sometimes I need to remove all indents on a method and then select it + format. Only then does the formatting work. Also here it doesn't remove white spaces.

3. On save: Tools -> options -> Text Editor -> Code Cleanup
Here I know I am able to have some configurations done when clicked on save. Also here a white space remover seems not to be there.

Overall I just find the Formatting options and keyboard shortcut options very limited. An option in VSCode for example is to copy your current line to a line below, I havent found this option yet in Visual Studio.
I love the Visual Studio for its IDE and for example test explorer, but formatting is such a huge thing that I feel like I'm missing something or Visual Studio needs to step up there game.

Would love what you guys think and I really hope that I am overlooking some functionality or something :)

๐ŸŒ
YouTube
youtube.com โ€บ watch
How To Format Code In Visual Studio 2022? - Next LVL Programming - YouTube
How To Format Code In Visual Studio 2022? In this informative video, weโ€™ll guide you through the essential features of code formatting in Visual Studio 2022....
Published ย  January 21, 2025
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ visualstudio โ€บ ide โ€บ reference โ€บ options-text-editor-c-cpp-formatting
Options, Text Editor, C/C++, Formatting - Visual Studio (Windows) | Microsoft Learn
You can also specify to only run the file for manually invoked formatting commands Format Document (Ctrl+K, Ctrl+D) or Format Selection (Ctrl + K, Ctrl + F). The Formatting section contains other subsections with more settings: Indentation, ...
๐ŸŒ
Visual Studio Marketplace
marketplace.visualstudio.com โ€บ items
Format on Save for VS2022 - Visual Studio Marketplace
Extension for Visual Studio - Automatically format document on save. Current release includes RemoveAndSort, FormatDocument, UnifyLineBreak, UnifyEndOfFile, TabToSpace, ForceUtf8WithBom with file extension filters.
Find elsewhere
๐ŸŒ
Yarkul
yarkul.com โ€บ home โ€บ how to auto format code in visual studio 2022?
How to Format Code in Visual Studio 2022? Shortcut
March 2, 2023 - Learn how to format Document or Selected part in the Visual Studio 2022. Read and remember hot keys. Screenshots with examples.
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to auto format code in Visual Studio - YouTube
In this video how to auto format code in visual studio#coding #visualstudio #programming
Published ย  November 7, 2023
๐ŸŒ
Reddit
reddit.com โ€บ r/visualstudio โ€บ how to format code completely?
r/VisualStudio on Reddit: How to format code completely?
October 5, 2021 -

Hi! I was wondering if there's a way to format the code automatically. VS has it's own formatter but it doesn't add semicolon automatically and it doesn't format empty space well enough. In VS code for example, when I format it formats everything well.

Couldn't find an extension for VS like prettier or beautify.

How can I automate this?

๐ŸŒ
Reddit
reddit.com โ€บ r/visualstudio โ€บ free auto formatting code extension for visual studio 2022
r/VisualStudio on Reddit: Free auto formatting code extension for visual studio 2022
September 10, 2021 -

hi some days ago I found an extension named "continuous formatting" the point of this extension is to format code as you type. the downside is it is not free, does anyone know similar extensions that are free? I know some extensions are there that format code when you save the file but I don't want them.

thanks.

๐ŸŒ
Medium
medium.com โ€บ @benjaminabt โ€บ auto-format-your-code-on-save-with-visual-studio-6ff479fe2182
Auto Format your Code on save with Visual Studio | by BEN ABT | Medium
November 27, 2024 - This can be activated in the Visual Studio options under Text Editor -> Code Cleanup and then check the box and select the profile.
๐ŸŒ
JetBrains
jetbrains.com โ€บ help โ€บ resharper โ€บ Enforcing_Code_Formatting_Rules.html
Apply formatting rules | ReSharper Documentation
If you are using ReSharper auto-formatting features, we recommend that you disable Visual Studio auto-formatting. You can do it in Visual Studio options (Tools | Options). For C# for example, clear the corresponding check-boxes on the Text Editor | C# | Code Style | Formatting | General options page.
๐ŸŒ
Codemia
codemia.io โ€บ knowledge-hub โ€บ path โ€บ how_do_you_auto_format_code_in_visual_studio
How do you auto format code in Visual Studio?
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises
๐ŸŒ
Damir's Corner
damirscorner.com โ€บ blog โ€บ posts โ€บ 20240105-AutoFormattingCSharpCode.html
Auto-formatting C# code | Damir's Corner
In Visual Studio Code, you install the extension and enable reformat on save in user settings. You'll most likely also have to choose CSharpier as the default formatter, because the C# Dev Kit extension also installs one.
๐ŸŒ
Unity
unity.com โ€บ how-to โ€บ formatting-best-practices-c-scripting-unity
Formatting Best Practices for C# Scripting & Code
In Visual Studio (Windows), go to Edit > Advanced > Format Document (Ctrl + K, Ctrl + D hotkey chord). If you want only to format white spaces and tab alignment, you can also use Run Code Cleanup (Ctrl + K , Ctrl + E) at the bottom of the editor.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-format-code-with-prettier-in-visual-studio-code
Format Code with Prettier in Visual Studio Code: Setup Guide | DigitalOcean
August 1, 2025 - Learn how to format code with Prettier in Visual Studio Code. This guide walks you through installing, configuring, and using Prettier for code formatting.
๐ŸŒ
TecAdmin
tecadmin.net โ€บ how-to-format-source-code-in-visual-studio-code
How to format source code in Visual Studio Code (VSCode) โ€“ TecAdmin
April 26, 2025 - Code formatting is essential for developers. A formatted code is easy to understand for other developers and allows us to find issues within the source code quickly. This article will help you to format source code in Visual Studio Code (VSCode) editor on various operating systems.