when I create a simple .cs file in VS Code in any folder, without a project setup or anything, it will format correctly using the Prettier extension (onSave).
But I cannot get the autoformatting to work when I open a C# file from unity. Or in a Unity Project.
In the left bottom bar I get an error: "Extension Prettier - Code Formatter cannot format Assets\Movement.cs" I've checked the developer console and there is no error or anything.
Prettier C# adds C# support to the Prettier code formatter. Like Prettier, it is opinionated and restricts style options to a minimum. It runs where Prettier runs, including CI and pre-commit hooks.
That's because Prettier can't format C#.
To format C# code:
Install C# VS Code extension by Microsoft
Add these to your VS Code settings.json
"editor.formatOnSave": true,
"[csharp]": {
"editor.defaultFormatter": "ms-dotnettools.csharp"
}
omnisharp.json
file at your unity project directory and set the formatting options (see options){
"FormattingOptions": {
"organizeImports": false,
"UseTabs": false,
"TabSize": 4,
"IndentationSize": 4
}
}
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