You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code无法用.editorconfig格式化C#文件,「格式化文档」功能无效

解决VS Code中C#项目EditorConfig格式化无效问题
  • 开启C#扩展的EditorConfig支持
    VS Code的C#扩展(ms-dotnettools.csharp)默认用Roslyn格式化,可能覆盖EditorConfig设置:

    1. 打开设置(快捷键Ctrl+,)
    2. 搜索omnisharp.enableEditorConfigSupport,确保勾选为true
  • 确认EditorConfig文件位置
    文件必须放在项目根目录(和.csproj同级),否则只会影响子目录文件,检查你的文件位置是否正确。

  • 排查编辑器缩进显示冲突
    编辑器显示3个空格可能是全局设置覆盖了EditorConfig:

    1. 打开设置,搜索editor.tabSize和editor.insertSpaces
    2. 将这两个选项设为inherit,让编辑器优先读取EditorConfig配置
  • 重启Omnisharp服务
    配置修改后需重启服务生效:

    1. 打开命令面板(快捷键Ctrl+Shift+P)
    2. 执行OmniSharp: Restart OmniSharp
  • 调整EditorConfig配置(可选)
    你的配置中indent_style = tab搭配indent_size = 3属于特殊组合,若想用3个空格替代tab,可修改为:

    [*.cs]
    indent_style = space
    indent_size = 3
    

内容的提问来源于stack exchange,提问作者Hung P.T.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 15:12:01