Visual Studio 禁用缺少 XML 注释警告

发布于 2024-12-13 07:44:28 字数 299 浏览 1 评论 0原文

我的项目有超过 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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

墟烟 2024-12-20 07:44:28

如上所述,一般来说,我认为不应忽略(抑制)这些警告。总而言之,解决警告的方法是:

  • 通过更改项目 Properties > 来抑制警告。 构建> 错误和警告 > 通过输入 1591 抑制警告
  • 添加 XML 文档标记(GhostDoc 可以是非常方便)
  • 通过编译器选项抑制警告取消
  • 选中项目 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:

  • Suppress the warning by changing the project Properties > Build > Errors and warnings > Suppress warnings by entering 1591
  • Add the XML documentation tags (GhostDoc can be quite handy for that)
  • Suppress the warning via compiler options
  • Uncheck the "XML documentation file" checkbox in project Properties > Build > Output
  • Add #pragma warning disable 1591 at the top of the respective file and #pragma warning restore 1591 at the bottom
ゞ花落谁相伴 2024-12-20 07:44:28

禁用警告:
转到项目属性(右键单击您的项目并从上下文菜单中选择属性)
转到“构建”选项卡
输入图像描述此处

将 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
enter image description here

Add 1591 to the Suppress warnings textbox
enter image description here

物价感观 2024-12-20 07:44:28

您还可以修改项目的 .csproj 文件,以在第一个 1591标记>。
最初来自 Alexandru Bucur 的文章在此

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    ...
    <NoWarn>1591</NoWarn>
  </PropertyGroup>
  ...
</Project>

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

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    ...
    <NoWarn>1591</NoWarn>
  </PropertyGroup>
  ...
</Project>
浪菊怪哟 2024-12-20 07:44:28

进入项目属性并取消选中生成 XML 文档选项。

取消选中 XML 文档file

重新编译,警告就会消失。

Go into project properties and uncheck the generate XML document option.

Uncheck XML documentation file

Recompile and the warnings should go away.

不乱于心 2024-12-20 07:44:28

Visual Studio 2022

我建议在 Visual Studio 中使用 .editorconfig 文件在所有解决方案中设置通用代码样式。

在这种情况下,只需将此代码手动添加到 .editorconfig 文件中:

# SA0001: XML comment analysis is disabled due to project configuration
dotnet_diagnostic.SA0001.severity = none

注意: 对于我来说,从编辑器配置设计器中抑制 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:

# SA0001: XML comment analysis is disabled due to project configuration
dotnet_diagnostic.SA0001.severity = none

NOTE: For me, suppressing SA0001 from the Editor Config designer not working.

Only manual setting rule in the file.

归途 2024-12-20 07:44:28

您可以使用 .editorconfig 文件在每个文件的基础上有选择地禁用此功能 - 例如,如果您有特定的源文件(或多个文件),您可以使用类似的内容:

# single file
[IgnoreThisFile.cs]
dotnet_diagnostic.CS1591.severity = none

# multiple files, matching on specific naming convention
[*{Type,Stuff,Things}.cs]
dotnet_diagnostic.CS1591.severity = none

请注意,我在管理此警告方面有过一致的混合经验,但在 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:

# single file
[IgnoreThisFile.cs]
dotnet_diagnostic.CS1591.severity = none

# multiple files, matching on specific naming convention
[*{Type,Stuff,Things}.cs]
dotnet_diagnostic.CS1591.severity = none

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).

网名女生简单气质 2024-12-20 07:44:28

这本来是一条评论,但我无法让它适应限制:

我很想仅为 Reference.cs 和 WebService 导入禁用它们。实际上,我正在使用宏来对文件执行此操作。只需打开文件并执行这个宏(在VS2010中测试):

Sub PragmaWarningDisableForOpenFile()
    DTE.ActiveDocument.Selection.StartOfDocument()
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.LineUp()
    DTE.ActiveDocument.Selection.Insert("#pragma warning disable 1591")
    DTE.ActiveDocument.Selection.EndOfDocument()
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.Insert("#pragma warning restore 1591")
    DTE.ActiveDocument.Save()
End Sub

真的没有办法自动执行此操作吗?每次自动生成的代码覆盖该文件时,您都必须重做此操作。

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):

Sub PragmaWarningDisableForOpenFile()
    DTE.ActiveDocument.Selection.StartOfDocument()
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.LineUp()
    DTE.ActiveDocument.Selection.Insert("#pragma warning disable 1591")
    DTE.ActiveDocument.Selection.EndOfDocument()
    DTE.ActiveDocument.Selection.NewLine()
    DTE.ActiveDocument.Selection.Insert("#pragma warning restore 1591")
    DTE.ActiveDocument.Save()
End Sub

There is really no way to do this automatically? You would have to redo this every time the auto-generated code overrides the file.

暖树树初阳… 2024-12-20 07:44:28

要修复违反此规则的问题,请通过向项目文件添加 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文