13

I like to have clean, "0 warnings" - projects in C#. This includes my project having XML comments for every public property and class.

Now I use entity framework with migrations (code first). The migrations are created by using "Add-Migration" which cause automatic code to be generated in the Migrations folder (standard behavior). I might want/need to modify these classes a bit but do not want to add Comments for the public classes created there.

I know I can disable the warnings using #pragma disable but again do not want to have to do this for every Migration-class.

So: Is there a possibility to use #pragma disable (or something similar) on a complete folder or namespace?

I do NOT want to use something like GhostDoc as a workaround.

Ole Albers
  • 8,715
  • 10
  • 73
  • 166
  • 2
    Small advice: fix all warnings. – General-Doomer May 21 '15 at 08:04
  • You might be right. But it feels like being a slave to technology if I have to comment not the code I created but the one that was created by VS. Well it's not Cyberdyne (yet) but still annoying and feels terribly "un-smart" :) – Ole Albers May 21 '15 at 08:09
  • 1
    XML comments on properties massively reduces readability and any good developer with her salt will read your code, not the generated comment docs. So turn off the generation of the XML docs and thus kill all such warnings and concentrate on writing readable code. – David Arno May 21 '15 at 08:30
  • 2
    I do **not** use _generated_ XML comments but add useful information there manually. (I agree that generated comments are rubbish, that's why I do not want something like GhostDoc). Personally I see great benefits in XML comments, especially because these information will be shown on Intellisense.I know there are two types of devs. Those who use XML comments, and those who don't. But Pros and Cons discussions would me nearly "religious" and would be OT to SO and especially to my problem. – Ole Albers May 21 '15 at 08:47
  • @DavidArno let's not forget about library developers, for example, who need to comment their code for clients, who are other developers. – DvS Jul 08 '20 at 07:55
  • 1
    Some of the comments here are unsettling. Many, many people use EF's automated code generation. And that generated code triggers C# warnings/errors. Just like Ole Albers, I don't want to be pestered by this generated code each time I add a Migration file. Those Migration files are generated and deleted a lot; it's a lot of manual work to suppress the warnings each time. – jeancallisti Oct 25 '21 at 08:56
  • @jeancallisti Yes, having to suppress every generated file is annoying, but I think they're referring to not using automatic generation of *XML comments*, not automatic code generation. I can +1 that since they're pretty much redundant and I'm always rewriting them. How useful is a bunch of comments like ```Sets and gets the Name``` on a ```public string Name {get; set;}``` *really*? I usually don't even bother to put comments on self-explanatory properties like Name or Id unless there's something functionally different about it compared to other types' properties of the same name. – AMG Jul 11 '23 at 15:52

2 Answers2

4

Add a new .editorconfig file to that specific folder with this content:

[*.cs]
generated_code = true
dotnet_analyzer_diagnostic.severity = none
VahidN
  • 18,457
  • 8
  • 73
  • 117
1

To suppress warnings for generated code in a project

  • Right-click the project in Solution Explorer, and then click Properties.
  • Click Code Analysis.
  • Select the Suppress results from generated code check box.

Reference: How to: Suppress Code Analysis Warnings for Generated Code

Matt
  • 153
  • 1
  • 6