Most of the warnings that currently I have at my project comes from code that was autogenerated. In most cases, it is (CA1062: Validate arguments of public methods). I noticed that even console hello word app generated by Visual Studio display warning (S1118: Utility classes should not have public constructors).
How I can disable warnings for autogenerated code? (migrations mostly)
As crgolden says, you can add // <auto-generated/> tag at the start of file. BUT I would be cautious with doing that to files where the generator tools chose to not add it. You specifically mention migrations - you are supposed to review them before commit, EF sometimes does surprising things (*). That review is also a good time to fix any warnings that bother you. If you care enough about the warning to leave it enabled, silencing it in migrations sets a bad precedent. And if you don't care about it, you can disable it globally.
My view of the auto-generated comment is that it belongs in files that are regenerated outside of your control, or frequently, or both. Since we use EF as example, ModelSnapshot is a good candidate, and the migration tools DO include it. <Migration>.Designer.cs files are also generated with it. And it should almost never be added by hand (**)
(*) delete one column and add another, you may find migration with rename action if they have similar types. Or your coleague did some change to code and forgot to generate migration for it - your migration will now include changes from both and his part will be untested.
(**) since every rule needs an exception, recently I was considering breaking this rule for a thirdparty library we imported into project as source files. In the end I decided to just set the whole project to warning level 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With