我得到这个警告:“缺少公开可见类型或成员的XML注释”。
如何解决这个问题?
我得到这个警告:“缺少公开可见类型或成员的XML注释”。
如何解决这个问题?
当前回答
来自@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
其他回答
还有另一种方法可以抑制这些消息,而不需要任何代码更改或pragma块。使用Visual Studio -转到项目属性>构建>错误和警告>抑制警告-将1591附加到警告代码列表。
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)
当然要向公开可见的类型和成员添加XML注释:)
///<Summary>
/// Gets the answer
///</Summary>
public int MyMethod()
{
return 42;
}
所有成员都需要这些<summary>类型的注释——这些注释也会显示在智能感知弹出菜单中。
得到此警告的原因是因为您已经将项目设置为输出文档xml文件(在项目设置中)。这对于类库(.dll程序集)很有用,这意味着.dll的用户可以在visual studio中获得API的智能感知文档。
我建议你买一份GhostDoc Visual Studio插件。使记录变得更容易。
您需要为显示警告的成员添加/// 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);
}
一个非常简单的方法是在.csproj文件中添加一个属性:
<Project>
<PropertyGroup>
...
<!--disable missing comment warning-->
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
...