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

VSCode中omnisharp.json与.editorconfig配置失效问题求助

OmniSharp格式化配置失效修复方案

排查与修复步骤

  • 确认omnisharp.json位置:必须放在工作区根目录,新版OmniSharp不再优先读取用户级配置文件。
  • 统一配置冲突:你的.editorconfig和omnisharp.json存在矛盾项(比如csharp_new_line_before_else和NewLineForElse取值相反),即使关闭了enableEditorConfigSupport,新版OmniSharp仍可能残留.editorconfig的缓存配置,建议将两者的对应项统一。
  • 清除OmniSharp缓存:打开VSCode命令面板(Ctrl+Shift+P),执行OmniSharp: Restart OmniSharp,同时删除工作区下的.omnisharp缓存文件夹后重启VSCode。
  • 检查VSCode全局设置:打开settings.json,确认"csharp.formatting.style"设置为"custom",如果是其他预设(如"Visual Studio")会覆盖自定义的OmniSharp配置。
  • 查看OmniSharp日志:执行OmniSharp: Logs命令,检查是否有配置加载失败的报错信息,定位具体问题。

验证方法

创建测试代码片段,格式化后检查访问器的大括号是否保持在同一行:

public string DemoProperty { get; set; }

当前提供的配置文件

.editorconfig

[*.cs]
csharp_new_line_before_open_brace = none
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true

omnisharp.json

{
"RoslynExtensionsOptions": {
    "enableAnalyzersSupport": true
},
"FormattingOptions": {
   "enableEditorConfigSupport": false,
   "newLine": "\n",
   "useTabs": false,
   "tabSize": 4,
   "indentationSize": 4,

   "NewLinesForBracesInTypes": false,
   "NewLinesForBracesInMethods": false,
   "NewLinesForBracesInProperties": false,
   "NewLinesForBracesInAccessors": false,
   "NewLinesForBracesInAnonymousMethods": false,
   "NewLinesForBracesInControlBlocks": false,
   "NewLinesForBracesInAnonymousTypes": false,
   "NewLinesForBracesInObjectCollectionArrayInitializers": false,
   "NewLinesForBracesInLambdaExpressionBody": false,

   "NewLineForElse": false,
   "NewLineForCatch": false,
   "NewLineForFinally": false,
   "NewLineForMembersInObjectInit": false,
   "NewLineForMembersInAnonymousTypes": false,
   "NewLineForClausesInQuery": false
}
}

内容的提问来源于stack exchange,提问作者wanzhi cui

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 17:15:29