我得到这个警告:“缺少公开可见类型或成员的XML注释”。
如何解决这个问题?
我得到这个警告:“缺少公开可见类型或成员的XML注释”。
如何解决这个问题?
当前回答
在将一个属性附加到一个方法后,我得到了这条消息
[webMethod]
public void DoSomething()
{
}
但正确的做法是:
[webMethod()] // Note the Parentheses
public void DoSomething()
{
}
其他回答
我想对这里列出的答案补充一些东西:
正如Isak所指出的,XML文档对于类库非常有用,因为它为Visual Studio中的任何消费者提供了智能感知。因此,一个简单而正确的解决方案是关闭任何顶级项目(如UI等)的文档,因为它不会在自己的项目之外实现。
此外,我想指出的是,警告只表示在公开可见的成员。因此,如果将类库设置为只公开它需要公开的内容,则无需记录私有成员和内部成员。
当然要向公开可见的类型和成员添加XML注释:)
///<Summary>
/// Gets the answer
///</Summary>
public int MyMethod()
{
return 42;
}
所有成员都需要这些<summary>类型的注释——这些注释也会显示在智能感知弹出菜单中。
得到此警告的原因是因为您已经将项目设置为输出文档xml文件(在项目设置中)。这对于类库(.dll程序集)很有用,这意味着.dll的用户可以在visual studio中获得API的智能感知文档。
我建议你买一份GhostDoc Visual Studio插件。使记录变得更容易。
5个选项:
Fill in the documentation comments (great, but time-consuming) Turn off the comment generation (in project properties) Disable the warning in project properties (in 'Project properties' go to Project properties -> Build > "Errors and warnings" (section), Suppress Warnings (textbox), add 1591 (comma separated list)). By default it will change Active Configuration, consider to change configuration to All. Use #pragma warning disable 1591 to disable the warning just for some bits of code (and #pragma warning restore 1591 afterwards) Ignore the warnings (bad idea - you'll miss new "real" warnings)
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
#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