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

如何解决这个问题?


当前回答

#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

其他回答

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

[webMethod]
public void DoSomething()
{
}

但正确的做法是:

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

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指令从行首开始

Jon Skeet的回答非常适用于使用VisualStudio进行构建。但是,如果您通过命令行构建sln(在我的例子中是通过Ant),那么您可能会发现msbuild忽略sln抑制请求。

添加到msbuild命令行解决了我的问题:

/p:NoWarn=1591
#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

在这里的后面,但是这个线程中的许多解决方案都专注于在项目或类中完全删除警告。

如果你想保留合法的警告,但删除一些-例如,当你使用swagger公开API时,WebApi控制器上的cancellationToken (API用户不需要这个-它是由DI提供的)。

很难看,但至少在这种情况下,取消令牌是最后一个参数。

    /// <summary>
    /// Creates a Service
    /// </summary>
    /// <param name="service">The Service Definition</param> (**note no cancellation token param**)
    /// <returns>A newly created item</returns>
    /// <response code="201">Returns the newly created service</response>
    /// <response code="400">If there are validation errors with the submitted json body</response>
    /// <response code="409">Conflict. The service already exists</response>
    /// <response code="500">Because life is never perfect</response>
    [ProducesResponseType(typeof(Service), 201)]
    [ProducesResponseType(400)]
    [ProducesResponseType(409)]
    [ProducesResponseType(500)]
    [HttpPost]
    public async Task<ActionResult> ServiceCreate([FromBody] ServicePostRequest service,
#pragma warning disable 1573  
        CancellationToken cancellationToken = default) //**note: no warning**
#pragma warning restore 1573
    {