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

如何阻止Roslyn(OmniSharp)分析EF Core迁移类并上报警告

解决方案

1. 开启OmniSharp的EditorConfig支持

VSCode的C#插件默认可能未启用EditorConfig读取,需要在VSCode settings.json 中添加如下配置:

"omnisharp.enableEditorConfigSupport": true

修改完成后按下 Ctrl+Shift+P(Mac为Cmd+Shift+P),执行 OmniSharp: Restart OmniSharp 重启插件生效。

2. 修正EditorConfig匹配规则

根据你存放.editorconfig的位置调整配置:

  • 如果.editorconfig直接放在EF Core迁移文件所在的Migrations目录下,使用如下最简配置即可:
root = true
[*.cs]
generated_code = true
dotnet_analyzer_diagnostic.severity = none
  • 如果.editorconfig放在项目根目录,需要指定迁移文件的目录匹配规则:
root = true
[Migrations/**/*.cs]
generated_code = true
dotnet_analyzer_diagnostic.severity = none

如果存在多个上下文拆分的迁移目录,对应调整匹配路径即可。

3. 补充特殊分析器适配配置

部分第三方分析器不会默认识别generated_code标记,你可以直接指定要屏蔽的警告ID,示例如下:

[Migrations/**/*.cs]
generated_code = true
# 替换为你实际遇到的警告ID,可添加多行
dotnet_diagnostic.CA1822.severity = none
dotnet_diagnostic.IDE0058.severity = none

4. 清理OmniSharp缓存

如果修改后仍不生效,按下Ctrl+Shift+P执行OmniSharp: Clear Cached Compilation State,之后再次重启OmniSharp即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.28 08:36:03