Visual Studio Code doesn't format C# code

I created a new file, set the C# language, and wrote some code. Then I pressed Ctrl + Shift + F (or F1Format Document). And got I the error

Sorry, but there is no formatter for 'csharp'-files installed.

Also, I installed C# Extension, but it didn't help. The Visual Studio Code version is 1.18.0.


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.


This works for me.

Note: If it is true then clear the checkbox and set it to true again. After that, you must restart Visual Studio Code.

Menu FilePreferencesSettings

Enter image description here


Visual Studio Code with OmniSharp doesn't format C# code without a .csproj file.

You can create a new project with dotnet new console with the .NET Core SDK.


  1. Browse the Visual Studio Code extension library, and make sure you've got the C# extension installed ms-dotnettools.csharp

    VS Code extensions pane showing C# OmniSharp extension

  2. Press Ctrl + , to open the Settings panel. Change the editor.formatOnType setting to be enabled. This wasn't enabled by default in my Visual Studio Code.

    VS Code settings window with editor.formatOnType setting

  3. Restart Visual Studio Code. It should now make code auto-format when you complete the line with a semicolon, or when you close the outer brace of a scope.

Note: this is a global setting for the editor, so it may enable auto-formatting for other languages and not just C#.

This was tested on Visual Studio Code version 1.43.1.