How to suppress all errors and warnings within namespace (or directory) using GlobalSuppressions.cs
I have a directory with generated API client code and it does not match coding standards configured within the solution. I would like to ignore all errors and warnings withing namespace or directory.
So far I tried the following code which is supposed to ignore multiple blank lines, but it doesn't work.
I also tried the namespace with actual code within it, so for example as below but still doesn't work. How to do it correctly?
16 Replies
what is
~N:
supposed to represent here?Namespace I guess - taken from docs and SO
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/documentation-comments#d42-id-string-format
https://stackoverflow.com/questions/48922211/visual-studio-globalsuppressions-cs-prefix-p-for-attribute-target-in-suppres
It's very hard to find actual documentation for this attribute
I'd have to disagree
SuppressMessageAttribute.Target Property (System.Diagnostics.CodeAn...
Gets or sets a fully qualified path that represents the code analysis target.
the official docs specifically give an example value for the
Target
property, and doesn't mention any of the stuff that the SO post referencesSingle example for single member is not the documentation at all. This page explains nothing.
it explains how to use the attribute
and it in fact works
as described in the official docs
without these attributes, I get the two warnings for
Bar()
with these attributes, they disappear
does this work for you if you try and apply it to non-generated code?Partially.
Doesn't work for
.
Also if I do this attribute as provided example from you, or example from me in this message I receive warning about legacy format, which is unacceptable.
so, it applies to anything in
My.Nested.Namespace
but not My.Nested.Namespace.Foo
?I mean, it applies to things inside
My.Nested.Namespace.Foo
, but it doesn't catch empty lines between comments and usings in above example, while in my understanding it's still within My.Nested.Namespace
namespace.ahhhh
so
that's probably simply impossible
the two empty lines there aren't part of any symbol
try adding some of the following to your source gen
although, that might have the same issue: they can only be attached to code elements, not files
if not that, you'll probably have to add a #pragma to the top of the file to suppress directly
not sure if you can write a #pragma to just suppress everything
ah, yeah
so
at the top of all your code gen files will just disable everything
hopefully
unless those issues don't quality as "warnings"
I see. Maybe it will be easier to add formatting to those files in the pipeline then. Thanks
Wasn't there something to mark source generated files by naming pattern or directive? Didn't that also disable code inspection?
not that I'm aware
the only naming pattern there is for source-gen files is
.g.i.cs
which is files probably already areIs this in a source generator's output, or are the files actually generated by some separate tool and exist on disk?
Because if it's the latter, just use an
.editorconfig
file to suppress it in the directoryWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.