dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 673 forks source link

csharp formatter not installed #4680

Open Od1Um opened 3 years ago

Od1Um commented 3 years ago

Issue Description

The formatter stopped working in one of the launches. Yesterday everything worked and the code was formatted, today VS Code gives an error: csharp formatter not installed

Settings jsom

{ "editor.suggestSelection": "first", "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "editor.fontFamily": "'Cascadia Code'", "workbench.colorTheme": "Cobalt2", "cSpell.language": "en, ru", "csharp.format.enable": true, "editor.fontLigatures": true, "editor.defaultFormatter": "ms-dotnettools.csharp", "editor.formatOnSave": true, "editor.formatOnType": true, "editor.cursorBlinking": "expand", "editor.formatOnPaste": true, "files.exclude": { "**/.git": true, "**/.DS_Store": true, "**/*.meta": true, "**/*.*.meta": true, "**/*.unity": true, "**/*.unityproj": true, "**/*.mat": true, "**/*.fbx": true, "**/*.FBX": true, "**/*.tga": true, "**/*.cubemap": true, "**/*.prefab": true, "**/Library": true, "**/ProjectSettings": true, "**/Temp": true }, "cSpell.userWords": [ "decuber" ] }

Expected Behavior

Actual Behavior

Logs

OmniSharp log

Starting OmniSharp server at 25.07.2021, 12:28:23 Target: s:\Projects\Development\Projects\Unity\My Games\Decuber\Decuber\Decuber.sln OmniSharp server started. Path: c:\Users\OdIUm\.vscode\extensions\ms-dotnettools.csharp-1.23.13\.omnisharp\1.37.12\OmniSharp.exe PID: 16616 [info]: OmniSharp.Stdio.Host Starting OmniSharp on Windows 6.2.9200.0 (x64) [info]: OmniSharp.Services.DotNetCliService DotNetPath set to dotnet System.IO.FileNotFoundException: P:\Development\Visual Studio 2019\MSBuild\Current\Bin\Microsoft.Build.dll в System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName) в OmniSharp.MSBuild.Discovery.MSBuildInstanceProvider.GetMSBuildVersion(String microsoftBuildPath) в D:\a\1\s\src\OmniSharp.Host\MSBuild\Discovery\MSBuildInstanceProvider.cs:строка 104 в OmniSharp.MSBuild.Discovery.Providers.MicrosoftBuildLocatorInstanceProvider.<>c.b__1_0(VisualStudioInstance instance) в D:\a\1\s\src\OmniSharp.Host\MSBuild\Discovery\Providers\MicrosoftBuildLocatorInstanceProvider.cs:строка 30 в System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() в System.Linq.Buffer`1..ctor(IEnumerable`1 source) в System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) в System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items) в OmniSharp.MSBuild.Discovery.MSBuildLocator.GetInstances() в D:\a\1\s\src\OmniSharp.Host\MSBuild\Discovery\MSBuildLocator.cs:строка 115 в OmniSharp.MSBuild.Discovery.Extensions.GetBestInstance(IMSBuildLocator msbuildLocator, Version minimumMSBuildVersion, ILogger logger, Boolean& invalidVSFound, Boolean& vsWithoutSdkResolver) в D:\a\1\s\src\OmniSharp.Host\MSBuild\Discovery\Extensions.cs:строка 109 в OmniSharp.MSBuild.Discovery.Extensions.RegisterDefaultInstance(IMSBuildLocator msbuildLocator, ILogger logger, DotNetInfo dotNetInfo) в D:\a\1\s\src\OmniSharp.Host\MSBuild\Discovery\Extensions.cs:строка 17 в OmniSharp.CompositionHostBuilder.Build(String workingDirectory) в D:\a\1\s\src\OmniSharp.Host\CompositionHostBuilder.cs:строка 71 в OmniSharp.Stdio.Host..ctor(TextReader input, ISharedTextWriter writer, IOmniSharpEnvironment environment, IServiceProvider serviceProvider, CompositionHostBuilder compositionHostBuilder, ILoggerFactory loggerFactory, CancellationTokenSource cancellationTokenSource) в D:\a\1\s\src\OmniSharp.Stdio\Host.cs:строка 49 в OmniSharp.Stdio.Driver.Program.<>c__DisplayClass0_1.
b__1() в D:\a\1\s\src\OmniSharp.Stdio.Driver\Program.cs:строка 74 в OmniSharp.HostHelpers.Start(Func`1 action) в D:\a\1\s\src\OmniSharp.Host\HostHelpers.cs:строка 29 [ERROR] Error: OmniSharp server load timed out. Use the 'omnisharp.projectLoadTimeout' setting to override the default delay (one minute).

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.58.2 C# Extension: 1.23.13

Dotnet Information ����� SDK ��� .NET (��ࠦ��騩 �� global.json): Version: 5.0.302 Commit: c005824e35 �।� �믮������: OS Name: Windows OS Version: 10.0.19042 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\5.0.302\ Host (useful for support): Version: 5.0.8 Commit: 35964c9215 .NET SDKs installed: 5.0.302 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |auto-using|Fudge|0.7.15| |better-comments|aaron-bond|2.1.0| |bracket-pair-colorizer|CoenraadS|1.0.61| |change-case|wmaurer|1.0.0| |code-spell-checker|streetsidesoftware|1.10.2| |code-spell-checker-russian|streetsidesoftware|0.2.10| |csharp|ms-dotnettools|1.23.13| |csharpsortusings|jongrant|0.0.3| |docomment|k--kato|0.1.20| |eppz-code|eppz|1.2.52| |material-icon-theme|PKief|4.8.0| |material-theme|zhuangtongfa|3.11.1| |namespace|adrianwilczynski|1.1.2| |night-owl|sdras|2.0.1| |one-dark-theme|mskelton|1.9.0| |shader|slevesque|1.1.5| |shaderlabvscodefree|amlovey|1.2.8| |theme-cobalt2|wesbos|2.2.5| |theme-dracula|dracula-theme|2.22.4| |theme-onedark|azemoh|0.6.0| |Theme-TomorrowKit|ms-vscode|0.1.4| |trailing-spaces|shardulm94|0.3.1| |unity-code-snippets|kleber-swf|1.3.0| |unity-debug|Unity|3.0.2| |unity-snippets|YclepticStudios|0.1.2| |vscode-icons|vscode-icons-team|11.5.0| |vscode-language-pack-ru|MS-CEINTL|1.58.8| |vscode-theme-darcula|rokoroku|1.2.3| |vscode-theme-onedark|akamud|2.2.3| |vscode-theme-superonedark|seansassenrath|0.0.15| |vscodeintellicode|VisualStudioExptTeam|1.2.14|;
Kyrike commented 3 years ago

Experiencing same issue Okay so uninstalling and reinstalling the csharp addon fixes it

eranimo commented 3 years ago

Reinstalling did not fix the issue for me.

JoeRobich commented 3 years ago

@Od1Um Is "editor.defaultFormatter": "ms-dotnettools.csharp", necessary? In my experience when I am working from a C# workspace it uses C# formatter as expected.

bubbleshoot9 commented 3 years ago

Reinstalling did not fix the issue for me.

xwiggen commented 3 years ago

same here after clean install, neither reinstall nor @JoeRobich setting does work. Ctrl-I shows dialog with no formatter installed for 'csharp' files with buttons install formatter and cancel.

update: apparently omnisharp does not run and I'm unable to start it with Ctrl-Shift-P Omnisharp Restart update: omnisharp restarts fine, I have 2 csprojects (one git submodule) of which I have to select one, this wasn't the case earlier. Works fine with this workaround.

JoeRobich commented 3 years ago

@Od1Um I see the following in your omnisharp log

System.IO.FileNotFoundException: P:\Development\Visual Studio 2019\MSBuild\Current\Bin\Microsoft.Build.dll

Do you have an incomplete install of VS on your system? Might try a repair.

Ciph3rzer0 commented 3 years ago

I installed this extension and VSCode doesn't recognize it as a csharp formatter. Searching on the marketplace for category:formatters csharp does not list this extension. Setting "editor.defaultFormatter": "ms-dotnettools.csharp" and formatting with shift+alt+F says the same thing, "Extension C# cannot format (filename).cs"

I eventually got it working by simply saving with "format on save" enabled. After this, now shift+alt+F formats properly, whereas before it said there was no formatter.

frankhale commented 2 years ago

I had this problem this morning and tried everything listed above. Adding "editor.defaultFormatter": "ms-dotnettools.csharp" explicitly to my settings seems to have fixed it. Not really sure why it broke but it was working as expected in prior days.

PatrikTegelberg commented 2 years ago

Tried all of the above. Added "editor.defaultFormatter": "ms-dotnettools.csharp" and checked all "format on ...". shift + alt + f still says "There is no formatter for csharp files installed". Installed OmniSharp because it was recommended and from Microsoft. Installed dotnet sdk, even though will never use it, just to maybe get indented c# code. Refusing to need an extension for indenting the code. Mad.