Visual Studio 禁用缺少 XML 注释警告
我的项目有超过 500 个 Missing XML Comment
警告。我知道我可以删除 XML 注释功能,或者在各处粘贴空注释片段,但我更喜欢一种通用解决方案,在其中我可以进行一项更改来禁用此类的所有警告。
我刚才所做的就是投入
///<Summary>
///
///</Summary>
或者
#pragma warning disable 1591
只是好奇这是否可能。
I have a project with over 500 Missing XML Comment
warnings. I know I can remove the XML Comment feature, or paste empty comment snippets everywhere, but I'd prefer a generic solution where I can make one change that disables all warnings of this type.
What I do just now is putting
///<Summary>
///
///</Summary>
or
#pragma warning disable 1591
was just curious if it would be possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
如上所述,一般来说,我认为不应忽略(抑制)这些警告。总而言之,解决警告的方法是:
Properties
> 来抑制警告。构建
>错误和警告
>通过输入 1591 抑制警告
Properties
> 中的“XML 文档文件”复选框构建
>输出
#pragma warning disable 1591
并在底部添加#pragma warning restore 1591
As suggested above, in general I don't think that these warnings should be ignored (suppressed). To summarise, the ways around the warning would be to:
Properties
>Build
>Errors and warnings
>Suppress warnings
by entering 1591Properties
>Build
>Output
#pragma warning disable 1591
at the top of the respective file and#pragma warning restore 1591
at the bottom禁用警告:
转到项目属性(右键单击您的项目并从上下文菜单中选择属性)
转到“构建”选项卡
将 1591 添加到抑制警告文本框
Disable the warning:
Go to the Project properties(Right click on your project and choose Properties from the context menu)
Go to the Build tab
Add 1591 to the Suppress warnings textbox
您还可以修改项目的
1591 标记>。
.csproj
文件,以在第一个最初来自 Alexandru Bucur 的文章在此
You can also modify your project's
.csproj
file to include a<noWarn>1591</noWarn>
tag inside of the first<PropertyGroup>
.Originally from Alexandru Bucur's Article Here
进入项目属性并取消选中生成 XML 文档选项。
重新编译,警告就会消失。
Go into project properties and uncheck the generate XML document option.
Recompile and the warnings should go away.
Visual Studio 2022:
我建议在 Visual Studio 中使用
.editorconfig
文件在所有解决方案中设置通用代码样式。在这种情况下,只需将此代码手动添加到
.editorconfig
文件中:注意: 对于我来说,从编辑器配置设计器中抑制
SA0001
不起作用。仅在文件中手动设置规则。
Visual Studio 2022:
I would recommend to use
.editorconfig
file in the Visual Studio to set a common code style across all solution.In this case, just add this code manually to the
.editorconfig
file:NOTE: For me, suppressing
SA0001
from the Editor Config designer not working.Only manual setting rule in the file.
您可以使用
.editorconfig
文件在每个文件的基础上有选择地禁用此功能 - 例如,如果您有特定的源文件(或多个文件),您可以使用类似的内容:请注意,我在管理此警告方面有过一致的混合经验,但在 VS2022 的当前版本(17.4.4+)中,它似乎仍然存在。确保
.editorconfig
在您的文件夹结构中处于足够“高”的级别,以便它适用于所有源文件(或者,根据您的需要在特定文件夹级别使用多个文件)。You can disable this selectively on a per-file basis using an
.editorconfig
file - for example, if you have a specific source file (or multiple files), you can use something like:Note that I've had mixed experiences with consistently managing this warning but in the current version (17.4.4+) of VS2022, it seems to stick. Make sure the
.editorconfig
is at a "high" enough level in your folder structure that it applies across all of your source files (or alternatively, use multiple files at specific folder levels depending on your needs).这本来是一条评论,但我无法让它适应限制:
我很想仅为 Reference.cs 和 WebService 导入禁用它们。实际上,我正在使用宏来对文件执行此操作。只需打开文件并执行这个宏(在VS2010中测试):
真的没有办法自动执行此操作吗?每次自动生成的代码覆盖该文件时,您都必须重做此操作。
This would have been a comment but I couldn't get it to fit the limitation:
I would love to disable them just for the Reference.cs and WebService imports. Actually, I'm using a macro to do it for a file. Just open the file and execute this macro (tested in VS2010):
There is really no way to do this automatically? You would have to redo this every time the auto-generated code overrides the file.
要修复违反此规则的问题,请通过向项目文件添加 true 来启用 XML 文档文件作为项目输出的一部分。
提及于:
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA0001.md#how-to-fix-violations
To fix a violation of this rule, enable the XML documentation file as part of the project output by adding true to your project file.
Mentioned at:
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA0001.md#how-to-fix-violations