我得到这个警告:“缺少公开可见类型或成员的XML注释”。

如何解决这个问题?


当前回答

插入一个XML注释。: -)

/// <summary>
/// Describe your member here.
/// </summary>
public string Something
{
    get;
    set;
}

乍一看,这似乎是个笑话,但实际上可能很有用。对我来说,思考方法对于私有方法的作用是有帮助的(当然,除非非常琐碎)。

其他回答

来自@JonSkeet的答案几乎完成了。如果您想为解决方案中的每个项目禁用它,可以将下面的行添加到.editorconfig文件中。

dotnet_diagnostic.CS1591.severity = none

https://github.com/dotnet/roslyn/issues/41171#issuecomment-577811906

https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2022

查看文件层次结构和优先级添加文件的位置:

https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2019#file-hierarchy-and-precedence

禁止XML注释的警告

(不是我的作品,但我发现它很有用,所以我包含了文章和链接)

http://bernhardelbl.wordpress.com/2009/02/23/suppress-warnings-for-xml-comments/

Here i will show you, how you can suppress warnings for XML comments after a Visual Studio build. Background If you have checked the "XML documentation file" mark in the Visual Studio project settings, a XML file containing all XML comments is created. Additionally you will get a lot of warnings also in designer generated files, because of the missing or wrong XML comments. While sometimes warnings helps us to improve and stabilize our code, getting hundreds of XML comment warnings is just a pain. Warnings Missing XML comment for publicly visible type or member … XML comment on … has a param tag for ‘…’, but there is no parameter by that name Parameter ‘…’ has no matching param tag in the XML comment for ‘…’ (but other parameters do) Solution You can suppress every warning in Visual Studio. Right-click the Visual Studio project / Properties / Build Tab Insert the following warning numbers in the "Suppress warnings": 1591,1572,1571,1573,1587,1570

当然要向公开可见的类型和成员添加XML注释:)

///<Summary>
/// Gets the answer
///</Summary>
public int MyMethod()
{
   return 42;
}

所有成员都需要这些<summary>类型的注释——这些注释也会显示在智能感知弹出菜单中。

得到此警告的原因是因为您已经将项目设置为输出文档xml文件(在项目设置中)。这对于类库(.dll程序集)很有用,这意味着.dll的用户可以在visual studio中获得API的智能感知文档。

我建议你买一份GhostDoc Visual Studio插件。使记录变得更容易。

#pragma warning disable 1591
#pragma warning disable 1591
#pragma warning disable 1572
#pragma warning disable 1571
#pragma warning disable 1573
#pragma warning disable 1587
#pragma warning disable 1570

I know this is a really old thread, but it's the first response on google so I thought I'd add this bit of information: This behavior only occurs when the warning level is set to 4 under "Project Properties" -> "Build". Unless you really need that much information you can set it to 3 and you'll get rid of these warnings. Of course, changing the warning level affects more than just comments, so please refer to the documentation if you're unsure what you'll be missing: https://msdn.microsoft.com/en-us/library/thxezb7y.aspx