Visual Studio Code doesn’t format C# code

If you have prettier as the default formatter as I do, you should do this:

  1. Open your vscode settings with these shortcut: ctrl + ,, or enter image description here

  2. Then click to “open settings (JSON)”: enter image description here

  3. This is where you should paste the below snippet.

This is my config:

{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "[csharp]": {
    "editor.defaultFormatter": "ms-dotnettools.csharp"
  }
}

For you to apply this configuration you need c# extension.

Leave a Comment