Please clarify the support of the suppress warnings for .NET Core 2.x code with Roslyn analysers (e.g. FxCop nuget)!
As stated here, this is particularly relevant for generated code.
btw, from code generated by Visual Studio "paste JSON/XML as classes", some prefilled attributes & suppress warning would help! Same applies for code generated from tools, e.g. from swagger code generator but it is off topic here!
In Roslyn analysers, the GeneratedCodeAttribute seems NOT to be supported.
The way to go seems to be the SuppressMessageAttribute in global suppression file: it works fine with the scope member, but it is not very applicable for generated code.
When the scope is set to namespace, I was expecting to have sub types disabled, but as the note says "It does not suppress the warning against types within the namespace."
I see it is a hot topic: https://github.com/dotnet/roslyn/issues/486
with a new scope being introduced to ignore types within namespace and target for Visual Studio 2019.
So please update this page when the new scope is defined!
I also tried to set the scope to type (changing from member and removing the member suffix in target to keep only the type), but here also without luck: the warning does not disappear as expected.
The current workaround is to have project-wide SuppressMessage, i.e. without scope and target.
Thus, creating dedicated .NET Standard library containing only the generated code will allow to apply these SuppressMessage only for it. It adds the avantage of an easier maintainability of such generated code.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@ericbl Thanks, we are aware that we need to update this topic. Related to https://github.com/dotnet/docs/issues/9046.
@ericbl You're probably aware, but I wanted to let you know that the new scope namespaceanddescendants is now available.
@ericbl Currently, source analysis using Roslyn analyzers doesn't support suppressing warnings just for generated code. See https://github.com/MicrosoftDocs/visualstudio-docs/issues/3230#issuecomment-492008665 and https://github.com/dotnet/roslyn/issues/6999.
The namespaceanddescendants scope for the SuppressMessageAttribute is available in VS 2019 and should help in your situation.
The remaining actionable item from this issue is to provide examples for the scopes for the SuppressMessageAttribute here.
When are you guys going to fill in the details for scope? For the following types:
This ticket is from Nov '18 !
Details for each of the scopes have been added previously in MicrosoftDocs/visualstudio-docs/issues/4404
Instructions to suppress messages for generated code are described in this issue:
https://github.com/dotnet/roslyn/issues/41171
I will add that to the doc.
Otherwise, you can view the required example code for a scoped suppression in the IDE by adding the suppression to the global suppression file and viewing the suppression in the preview window. I will add a link in the doc to make it easier to find this info.
Most helpful comment
When are you guys going to fill in the details for scope? For the following types:
This ticket is from Nov '18 !