Visual Studio不会抑制MVC1000警告

发布于 2025-02-04 04:14:44 字数 1207 浏览 1 评论 0原文

我们的一个项目存在很多问题,这些问题目前会导致数千个警告。这导致了一个新警告在开发过程中未被认可的问题。由于我们现在无法通过整个代码库解决所有警告,因此我们决定暂时禁用几种类型的警告。

我们添加了一个.editorConfig文件,并尝试使用dotnet_diarostic规则禁用某些警告:

[*.cs]
dotnet_diagnostic.CS0219.severity = none
dotnet_diagnostic.CS1998.severity = none
dotnet_diagnostic.CS4014.severity = none
dotnet_diagnostic.MVC1000.severity = none

这是针对前三个规则的预期工作的,但是使用Code 的警告> MVC1000仍然出现在Visual Studio 2019(16.11.15)的错误列表中。这真的很奇怪,因为Visual Studio似乎在.editorConfig文件中读取和理解该行,正如以下屏幕截图中可以看到的:

​严重性也反映在.editorConfig文件中。

有人知道为什么Visual Studio忽略了这条线,而不是其他三行?这一原因是否与视觉工作室定义的规则与分析仪定义的规则之间的差异联系在一起?有解决这个问题的解决方案吗?

更新:

我注意到某些cs0219警告仍然出现在错误列表中,所有这些警告均来自.cshtml文件,很有意义,因为现在只有.cs文件在.editorConfig文件中配置,这将导致所有MVC1000显示的规则。现在,我也将文件更改为.cshtml文件的appyly,现在警告不再显示在源文件中,但它们仍然显示在错误列表中:

[*.{cs,cshtml}]
dotnet_diagnostic.CS0219.severity = none
dotnet_diagnostic.CS1998.severity = none
dotnet_diagnostic.CS4014.severity = none
dotnet_diagnostic.MVC1000.severity = none

One of our projects has a lot of issues that cause over thousand warnings right now. This leads to the problem that new warnings go unrecognized during development. Since we cannot solve all warnings through the whole code base right now, we decided to temporarily disable several types of warnings.

We added a .editorconfig file and tried to disable some warnings using dotnet_diagnostic rules:

[*.cs]
dotnet_diagnostic.CS0219.severity = none
dotnet_diagnostic.CS1998.severity = none
dotnet_diagnostic.CS4014.severity = none
dotnet_diagnostic.MVC1000.severity = none

This works exactly as intended for the first three rules, however the warnings with the code MVC1000 still appear in the error list of Visual Studio 2019 (16.11.15). This is really strange, cause Visual Studio seems to read and understand the line in the .editorconfig file, as it can be seen in the following screenshot:

Screenshot

Using the Visual Studio UI to change the severity also reflects in the .editorconfig file.

Does anyone have an idea why Visual Studio ignores this line, but not the other three lines? Is the reason for this somehow linked to the difference between rules defined by Visual Studio and rules defined by an analyzer? Is there any solution to this problem?

Update:

I noticed that some of the CS0219 warnings still appear in the error list and that all of these warnings come from .cshtml files, which makes sense, since right now only .cs files are configured in the .editorconfig file and this causes all MVC1000 rules to be shown. I now changed the file to appyly for .cshtml files, too, and now the warnings are not shown in the source files anymore, but they still appear in the error list:

[*.{cs,cshtml}]
dotnet_diagnostic.CS0219.severity = none
dotnet_diagnostic.CS1998.severity = none
dotnet_diagnostic.CS4014.severity = none
dotnet_diagnostic.MVC1000.severity = none

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文