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)?
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.
Use a #pragma warning (C#) or Disable (Visual Basic) directive to suppress the warning for only a specific line of code.
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.
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.
Do your classes have the [GeneratedCode] attribute? If so you can get FxCop to ignore them:
Using an FxCop project:
- Open your FxCop project in FxCop
- Choose Project -> Options -> Spelling & Analysis
- Check Suppress analysis results against generated code
- Click OK
Via the command-line:
- 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
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