23

The C# compiler shows a warning (CS1591), if a public member is undocumented:

Warning ... Missing XML comment for publicly visible type or member ...

That includes all properties, methods, classes, enum value, etc.

Question: Is there a way to configure that type of warning to only mark undocumented methods? I use Visual Studio 2010 Ultimate and ReSharper 8.2.

Example:

public class MyClass // warning
{
    public MyClass(int x) { ... } // warning

    public void DoSomething() { ... } // warning

    public int MyProp { get; private set; } // prevent this warning
}

public enum MyEnum // warning
{
    X = 0, // prevent this warning
    Y = 1 // prevent this warning
}
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Christian St.
  • 1,751
  • 2
  • 22
  • 41
  • 5
    Thanks for downvoting a question, without leaving a comment!!! – Christian St. Sep 15 '14 at 11:55
  • Possible duplicate of [Visual Studio Disabling Missing XML Comment Warning](http://stackoverflow.com/questions/7982525/visual-studio-disabling-missing-xml-comment-warning) – Fenton Dec 30 '15 at 08:50
  • 2
    @Fenton completely different question, OP here is asking for disabling comment warnings in specific areas of code, OP in your link is just trying to disable comment warnings in entire project. Also I'm wondering has the answers for this possibly changed in newer versions of visual studio? I think with Roslyn analyser you can create custom rules but I wouldn't know where to start with it. – daeden Jan 04 '19 at 10:59

5 Answers5

33

You can disable it for the entire assembly if you wish.

Project Properties > Build tab > Suppress warnings: 1591

source: https://stackoverflow.com/a/13414522

Vitaliy Ulantikov
  • 10,157
  • 3
  • 61
  • 54
Chris Marisic
  • 32,487
  • 24
  • 164
  • 258
  • 3
    But this also removes the warning for public types and public (or protected) methods and constructors inside them, and he wanted to keep the warning for those members. – Jeppe Stig Nielsen Feb 23 '18 at 09:49
8

No, there is no way. The warning is generated if /doc option is specified. This options does not have any parameters to document methods only. Thus any entry that added to documentation is checked.

You can however disable warning with pragma warning, but it's not very convenient IMO, even if you group fields and properties.

Petr Abdulin
  • 33,883
  • 9
  • 62
  • 96
4

Add [NoWarn] on the *.csproj file to disable it.

  <PropertyGroup>
    <NoWarn>$(NoWarn);1591</NoWarn>
    <RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
    <EnableNETAnalyzers>true</EnableNETAnalyzers>
    <AnalysisMode>AllEnabledByDefault</AnalysisMode>
    <AnalysisLevel>latest</AnalysisLevel>
  </PropertyGroup>
  • 1
    This doesn't work reliably for me, unfortunately. (Using VS 2019 16.11) Even with `CS1591` or `$(NoWarn);CS1591` or `$(NoWarn);1591` I'll still see CS1591 messages in the Error List - but _sometimes_ I don't. _le sigh_ – Dai Jan 24 '22 at 14:50
  • IMHO this should be the answer – DanielV Jun 01 '23 at 11:51
3

In current Versions of Visual Studio you can use the SuppressMessageAttribute on a type or member.

[System.Diagnostics.CodeAnalysis.SuppressMessage("Compiler", "CS1591:Missing XML comment for publicly visible type or member", Justification = "<Pending>")]

More details about the attribute can be found here: https://learn.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?view=vs-2019

Steffen
  • 3,327
  • 2
  • 26
  • 30
  • 1
    This doesn't seem to work anymore in VS2022. They added an .editorconfig to control it instead: https://learn.microsoft.com/en-us/visualstudio/code-quality/in-source-suppression-overview?view=vs-2022#suppress-violations-using-the-editorconfig-file – carlin.scott May 18 '22 at 20:47
0

You can disable this warning for specific parts of your code by using #pragma warning disable CS1591, and later restore it with #pragma warning restore CS1591.

Example:

public class MyClass // warning
{
    public MyClass(int x) { ... } // warning

    public void DoSomething() { ... } // warning

#pragma warning disable CS1591 // Disable warning: "Missing XML comment for publicly visible type or member"
    public int MyProp { get; private set; } // this won't get a warning due to the #pragma
#pragma warning restore CS1591
}

Unfortunately this requires manually wrapping non-methods with these #pragma directives, but it's the only way to disable the warning selectively.

Aaron Franke
  • 3,268
  • 4
  • 31
  • 51