18

is there any way to auto-format HTML and Javascript code on saving in Visual Studio like Visual Studio Code?

Mohammad Ali Rony
  • 4,695
  • 3
  • 19
  • 33
  • **See Also**: [How do you auto format code in Visual Studio?](https://stackoverflow.com/q/5755942/1366033) – KyleMit May 05 '21 at 18:53

2 Answers2

25

Since Visual Studio 2022 17.1 there is a builtin Feature to run code formatting on save (see devblogs.microsoft), meaning there is no need to install extensions like Format document on Save.

enter image description here

Be aware that there is a failure regarding the merge view when using the autoformat option - github code cleanup - merge bug.

Kraego
  • 2,978
  • 2
  • 22
  • 34
8

The plugin Format document on Save seems to to do what you ask:

Enables auto formatting of the code when you save a file. Visual Studio supports auto formatting of the code with the Ctrl + E , D or Ctrl + E , F key shortcuts but with this extension the command Format Document is executed on Save.

KyleMit
  • 30,350
  • 66
  • 462
  • 664
GrafiCode
  • 3,307
  • 3
  • 26
  • 31