I created a new file, set the C# language, and wrote some code. Then I pressed Ctrl + Shift + F (or F1 → Format 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.
The code formatting is available in Visual Studio Code through the following shortcuts: On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.
Open up VSCode settings in UI mode by selecting File > Preferences > Settings or press Ctrl + ,. Input “formatter” in the search box. Once you see Editor: Default Formatter section, select . This setting allows you to define a default formatter which takes precedence over all other formatter settings.
If you have prettier as the default formatter as I do, you should do this:
Open your vscode settings with these shortcut: ctrl + ,
, or
Then click to "open settings (JSON)":
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With