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

如何解决这个问题?


当前回答

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)

其他回答

一个非常简单的方法是在.csproj文件中添加一个属性:

<Project>
    <PropertyGroup>
        ...     
        <!--disable missing comment warning-->
        <NoWarn>$(NoWarn);1591</NoWarn>
    </PropertyGroup>
...

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)

还有另一种方法可以抑制这些消息,而不需要任何代码更改或pragma块。使用Visual Studio -转到项目属性>构建>错误和警告>抑制警告-将1591附加到警告代码列表。

来自@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注释。: -)

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

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