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

如何解决这个问题?


当前回答

我想对这里列出的答案补充一些东西:

正如Isak所指出的,XML文档对于类库非常有用,因为它为Visual Studio中的任何消费者提供了智能感知。因此,一个简单而正确的解决方案是关闭任何顶级项目(如UI等)的文档,因为它不会在自己的项目之外实现。

此外,我想指出的是,警告只表示在公开可见的成员。因此,如果将类库设置为只公开它需要公开的内容,则无需记录私有成员和内部成员。

其他回答

您需要为显示警告的成员添加/// Comment。

参见下面的代码

public EventLogger()
{
    LogFile = string.Format("{0}{1}", LogFilePath, FileName);
}

显示警告 缺少公开可见类型或成员'.EventLogger()'的XML注释

我为成员添加了评论,警告消失了。

///<Summary>
/// To write a log <Anycomment as per your code>
///</Summary>
public EventLogger()
{
    LogFile = string.Format("{0}{1}", LogFilePath, FileName);
}

插入一个XML注释。: -)

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

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

这是因为您的项目属性中指定了一个XML文档文件,而您的方法/类是公共的,缺乏文档。 你可以:

禁用XML文档: 右键单击您的项目->属性->“构建”选项卡->取消选中XML文档文件。 坐下来自己写文档吧!

XML文档的总结如下:

/// <summary>
/// Description of the class/method/variable
/// </summary>
..declaration goes here..

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

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)