OmniSharp formatter does not format C# files

Viewed 214

The installed ms-dotnettools.csharp (v1.25.0) extension does not seem to format the C# code : my C# files witch I try to format popups me about missing C# formatter

Visual Studio Code
There is no formatter for 'csharp' files installed.
[Cancel] [Install Formatter...]

I open in the VSCode the entire root folder, containing several projects (C#, Angular etc.), and when opening individual Cs files and try to Shift+Alf+F to format the file, it asks me for the formatter.

enter image description here

I have the following VSCode configuration

Visual Studio Code
Version: 1.67.2 (user setup)
Commit: c3511e6c69bb39013c4a4b7b9566ec1ca73fc4d5
Date: 2022-05-17T18:15:52.058Z (2 wks ago)
Electron: 17.4.1
Chromium: 98.0.4758.141
Node.js: 16.13.0
V8: 9.8.177.13-electron.0
OS: Windows_NT x64 10.0.19044

also this .net installs

.NET SDK (reflecting any global.json):
 Version:   5.0.408
 Commit:    da985e2a23

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.408\

Host (useful for support):
  Version: 5.0.17
  Commit:  6a98414363

.NET SDKs installed:
  3.1.419 [C:\Program Files\dotnet\sdk]
  5.0.407 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]

I've checked that, reset it and restarted VSCode, but it has any effect:

enter image description here

1 Answers

You need to either update .Net to 6+ or install a previous version of Omnisharp.

Version 1.25.0 requires .Net 6+. If that's not an option for your environment then you can install a previous version of the Omnisharp extension.

In order to do this, press ctrl/cmd + shift + x to bring the extensions side panel, then click on the configurations wheel and select 'Install another version'.

I tried 1.23.12 and the formatter is working now.

If you run into this issue again you can check the output of the extension to check what could be causing it.

I'm not sure if you found it already, but I'll leave it here in case someone else needs it.

Related