I recently discovered a great tool by Microsoft which is called FxCop.
What is FxCop
FxCop is a free static code analysis tool from Microsoft that checks .NET managed code assemblies for conformance to Microsoft's .NET Framework Design Guidelines.
What it did for me
I used it in my own project. The first time I analysed it with FxCop, a lot of messages were printed (over 100). But not all rules which FxCop checks were really necessary for my project. So I disabled them global in the FxCop project or local in my code using the
For example I disabled "AssembliesShouldHaveValidStrongNames" and "DoNotDeclareVisibleInstanceFields", ... in the FxCop project and locally I supressed the message "IdentifiersShouldBeCasedCorrectly" with the attribute
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "OBB")] at the OBB class. But of course the most rule violations were fixed changing the code. Otherwise it would have been senseless to use FxCop.
FxCop doesn't only find design issues, it also finds real coding failures and possible performance problems. For example FxCop found a wrong used
ArgumentException in my project.
So I can highly recommend to use FxCop with OpenTK or any other .Net project.
I tested OpenTK with the FxCop rule settings for my project and it printed over 11334 messages. But most of them could be disabled for the OpenTK project. For example "AvoidUncalledPrivateCode". But I also saw a wrong used
ArgumentException in OpenTK.Utilities.
It was a real pain in the ass when I first started the FxCop analysis and I saw the bunch of rule violation messages. But soon it felt better and better after I have fixed the first problems and the rule violations stated by FxCop became less.
How to use
- You can download the latest version here.
- Start the program and a add a target (Dll, Exe) with "Menu" -> "Project" or context menu, ...
- Press the "Analyse" button.
- When the analyse is finished, you will see a list of messages with rule violations. Click on a list item to see the details in the "Properties" tab.
- (In the "Rules" tab you can disable certain rules.)
Note that FxCop could copy the right
SuppressMessageAttribute string to the clipboard. So you won't have to write the attributes yourself to suppress a certain message. Just paste them at the right place. To do so, open the context menu for a message in the list and click "Copy As" -> "SuppressMessage".
Don't forget to compile your project with the symbol "CODE_ANALYSIS" to suppress messages.
I've added the FxCop project to the sources of my project. Feel free to use it as a starter or copy some parts from the FxCop Xml-Project-File.
So what do you thing about FxCop?