Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Analysis on a Code Generator Generated File - How to Suppress Warnings?

We run Code Analysis on all our source files. One of our source files is a Linq-To-SQL generated file, which we have no control over the generated output. The generated code is producing Code Analysis warnings that I would like to suppress. Is there any way I can suppress CA warnings in a code generated file that doesn't involve creating attributes and/or pragma's in the code itself (which will get overwritten each time the file is generated)?

like image 624
Randy Minder Avatar asked Feb 08 '10 13:02

Randy Minder


People also ask

How do you suppress Code Analysis warnings?

If you migrate a project to Visual Studio 2019, you might suddenly be faced with a large number of code analysis warnings. If you aren't ready to fix the warnings, you can suppress all of them by selecting Analyze > Build and Suppress Active Issues.

Which number is used to suppress the warning in a code?

Use a #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code.

How do I disable a specific warning in Visual Studio?

Turn off the warning for a project in Visual StudioSelect the Configuration Properties > C/C++ > Advanced property page. Edit the Disable Specific Warnings property to add 4996 . Choose OK to apply your changes.

What is pragma warning in C#?

C# provides a feature known as the #pragma feature to remove the warnings. Sometimes we declare a variable but do not use the variable anywhere in the entire program so when we debug our code the compiler gives a warning so using the #pragma we can disable these types of warnings.


1 Answers

Do your classes have the [GeneratedCode] attribute? If so you can get FxCop to ignore them:

Using an FxCop project:

  1. Open your FxCop project in FxCop
  2. Choose Project -> Options -> Spelling & Analysis
  3. Check Suppress analysis results against generated code
  4. Click OK

Via the command-line:

  1. Pass the /ignoregeneratedcode switch, for example:
     FxCopCmd.exe /file:MyAssembly.dll /out:AnalysisResults.xml /ignoregeneratedcode

http://blogs.msdn.com/fxcop/archive/2008/02/28/faq-how-do-i-prevent-fxcop-1-36-from-firing-warnings-against-generated-code.aspx

like image 158
Paolo Avatar answered Sep 20 '22 04:09

Paolo