20

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.

7
  • 2
    Small advice: fix all warnings. Commented May 21, 2015 at 8: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" :) Commented May 21, 2015 at 8: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. Commented May 21, 2015 at 8: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. Commented May 21, 2015 at 8:47
  • 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. Commented Oct 25, 2021 at 8:56

3 Answers 3

13

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

[*.cs]
generated_code = true
dotnet_analyzer_diagnostic.severity = none
Sign up to request clarification or add additional context in comments.

1 Comment

It is also possible to use the root .editorconfig and specify the path, e.g. [src/Migrations/*.cs] instead of [*.cs].
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

2 Comments

That checkbox is already set. My guess would be that this only works for ".designer.*"-files.
In Visual Studio 2019 I don't have a "code analysis" entry in the Properties panel of a solution folder.
0

In addition to the answer of @VahidN

If you want to ensure that no settings from any higher-level .editorconfig files are applied to this part of the codebase, add the root=true property to the .editorconfig file:

# top-most EditorConfig file
root = true

Ref

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.