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

如何解决这个问题?


当前回答

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

其他回答

In your solution, once you check the option to generate XML Document file, it start checking your public members, for having the XMLDoc, if they don't, you'll receive a warning per each element. if you don't really want to release your DLL, and also you don't need documentations then, go to your solution, build section, and turn it off, else if you need it, so fill them, and if there are unimportant properties and fields, just surpass them with pre-compiler instruction #pragma warning disable 1591 you can also restore the warning : #pragma warning restore 1591

Pragma用法:在代码中任何你得到编译器警告的地方之前…(对于文件,把它放在头文件中,你不需要再次启用它,对于单个类环绕一个类,或方法环绕一个方法,或…你也不需要把它包装起来,你可以随意地调用它并恢复它(在文件的开始处开始,并在方法中结束)),编写以下代码:

#pragma警告禁用1591 如果你需要恢复它,使用: #pragma警告恢复1591

这里有一个例子:

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using RealEstate.Entity.Models.Base;

namespace RealEstate.Models.Base
{
    public class CityVM
    {

#pragma warning disable 1591

        [Required]
        public string Id { get; set; }

        [Required]
        public string Name { get; set; }

        public List<LanguageBasedName> LanguageBasedNames { get; set; }

        [Required]
        public string CountryId { get; set; }

#pragma warning restore 1591

        /// <summary>
        /// Some countries do not have neither a State, nor a Province
        /// </summary>
        public string StateOrProvinceId { get; set; }
    }
}

注意,pragma指令从行首开始

文件>编辑>查看项目(点击)

下拉弓的底部(点击打开/当前工作>属性), 打开项目属性页在“构建”下的“输出”。取消选中“XML文档”复选框。

重建,没有警告。

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

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

XML文档的总结如下:

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

在将一个属性附加到一个方法后,我得到了这条消息

[webMethod]
public void DoSomething()
{
}

但正确的做法是:

[webMethod()] // Note the Parentheses 
public void DoSomething()
{
}

来自@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