7

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 Answer 1

12

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
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.