Reputation: 1911
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
}
Upvotes: 35
Views: 27939
Reputation: 56
In my case, I can't add any code that would be committed to the repo. So changing the .csproj file is not an option. So I added an entry to Directory.Build.Props and then added that file to my .gitignore file since I will never be making any changes to that file.
In the section you need to add $(NoWarn);1591 So in my case it ends up like this:
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
That's the only thing that finally worked for me.
Upvotes: 0
Reputation: 1553
Add this in your .csproj
<PropertyGroup>
...
<NoWarn>$(NoWarn);1591</NoWarn> <-- this line
...
</PropertyGroup>
Upvotes: 0
Reputation: 4042
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.
Upvotes: 4
Reputation: 3156
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>
Upvotes: 8
Reputation: 3516
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
Upvotes: 5
Reputation: 33098
You can disable it for the entire assembly if you wish.
Project Properties > Build tab > Suppress warnings: 1591
source: https://stackoverflow.com/a/13414522
Upvotes: 34
Reputation: 35225
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.
Upvotes: 12