简体   繁体   English

OmniSharp 格式化程序不格式化 C# 文件

[英]OmniSharp formatter does not format C# files

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安装的ms-dotnettools.csharp (v1.25.0) 扩展似乎没有格式化 C# 代码:我的 C# 文件,我尝试格式化弹出窗口,提示我缺少 ZD7EFA19FBE7D3972FD5ADB60242 格式

Visual Studio Code视觉工作室代码
There is no formatter for 'csharp' files installed.没有安装“csharp”文件的格式化程序。
[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.我在 VSCode 中打开整个根文件夹,其中包含几个项目(C#、Angular 等),当打开单个 Cs 文件并尝试使用 Shift+Alf+F 格式化文件时,它会询问我格式化程序。

在此处输入图像描述

I have the following VSCode configuration我有以下 VSCode 配置

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 也安装

.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:我已经检查过了,重置它并重新启动 VSCode,但它有任何效果:

在此处输入图像描述

You need to either update.Net to 6+ or install a previous version of Omnisharp.您需要将.Net 更新到 6+ 或安装以前版本的 Omnisharp。

Version 1.25.0 requires.Net 6+.版本 1.25.0 需要 .Net 6+。 If that's not an option for your environment then you can install a previous version of the Omnisharp extension.如果这不是您的环境的选项,那么您可以安装以前版本的 Omnisharp 扩展。

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'.为此,请按 ctrl/cmd + shift + x 打开扩展侧面板,然后单击配置轮和 select '安装另一个版本'。

I tried 1.23.12 and the formatter is working now.我尝试了 1.23.12 并且格式化程序现在正在工作。

If you run into this issue again you can check the output of the extension to check what could be causing it.如果您再次遇到此问题,您可以检查扩展的 output 以检查可能导致它的原因。

I'm not sure if you found it already, but I'll leave it here in case someone else needs it.我不确定你是否已经找到它,但我会把它留在这里以防其他人需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM