Suppress CS0618 for entire file [Answered]
Can I suppress CS0618 for an entire file? I tried with
[System.Diagnostics.CodeAnalysis.SuppressMessage("Warning", "CS0618: Type or member is obsolete", Justification = "Some reason")]
but it doesn't look correct. How can I achieve this?
I want to avoid to #pragma warning disable CS0618 // Type or member is obsolete
on each single occurrence. And I want to avoid a global setting.16 Replies
can't you
#pragma warning disable {CODE}
at the start of the file and then #pragma warning restore {CODE}
at the end?
I haven't done it in a while so I'm not certainI suppose yes
Though, the one shown is what the team prefers seeing
uhh not hugely familiar with with CodeAnalysis attributes but can't you create a global one on the assembly targeted at a specific type? I vaguely remember being able to target a namespace
yes I can but the problem is the same,
SuppressMessage
uses strings for the category and I don't know what the category is. No clue how to find that from the documentation for CS0618it's called "Compiler Warning (level 2) CS0618". No idea what the category is
IDE0079, for example, shows the category very clearly -> https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0079
IDE0079: Remove unnecessary suppression - .NET
Learn about code analysis rule IDE0079: Remove unnecessary suppression
but those warning of the compiler don't really tell the category in the docs
interesting, can't see the full name of the error anywhere
though that seems to be the same for all CS errors
eh.......... I know
I got very frustrated with this
aaaah, okay, so, I think that CA and CS are entirely different things
the CS warning codes are from Roslyn and CA is legacy stuff
I started to think exactly that
so I think you have no choice but to use pragmas when dealing with roslyn analyzer errors
fair
At least I know I did all I could
thank you for looking into this
Appreciated
no worries, just write a strongly worded email to management about using legacy analyzers and then carry on with your day to
/close
when you're happy it's solved That's a good advice 😄
Thank you again
✅ This post has been marked as answered!