Reputation: 48432
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)?
Upvotes: 5
Views: 4858
Reputation: 3577
The PLINQO (Linq-to-SQL) CodeSmith templates also generate this attribute for you automatically. Most add-in's are also starting to ignore partial classes that are generated with ".generated" in the filename.
[System.CodeDom.Compiler.GeneratedCode("CodeSmith", "5.0.0.0")]
Upvotes: 0
Reputation: 109035
You can work around the lack of GeneratedCode
attribute by using your own branch of the partial classes to apply that attribute. This will mean that any custom code you add (including implementing partial methods) will be excluded. Eg.:
namespace MyApp.DB {
[GeneratedCode("LINQ To SQL", "4.0")]
internal partial class MyAppDataContext {
}
// Repeat for each entity
}
Upvotes: 2
Reputation: 3428
If you are using the FxCop GUI you could simply exclude these issues within the FxCop project. Just right click the issue and select Exclude where you can than also add a comment.
But if you run FxCop in the Output Window I do not have a clue. Maybe you could check if it is possible to create a module-level SuppressMessage and paste it into the AssemblyInfo.cs. But I don't think so.
Upvotes: 0
Reputation: 22638
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
Upvotes: 5