Prettier not formatting Unity C# Code - "Cannot format Movement.cs"

Viewed 3028

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.

1 Answers

That's because Prettier can't format C#.

To format C# code:

  1. Install C# VS Code extension by Microsoft

  2. Add these to your VS Code settings.json

"editor.formatOnSave": true,
"[csharp]": {
  "editor.defaultFormatter": "ms-dotnettools.csharp"
}
  1. Create a omnisharp.json file at your unity project directory and set the formatting options (see options)
{
  "FormattingOptions": {
    "organizeImports": false,
    "UseTabs": false,
    "TabSize": 4,
    "IndentationSize": 4
  }
}
Related