Skip to main content

onebit_26

Note: This is part of a series, you can find the rest of the parts in the series index.

Microsoft has offered a great tool called fxCop for a number of years now. This free tool takes your compiled .NET code and runs it against a number of rules to check things like security, compatibility, globalisation and so on.

imageSome of the higher SKU’s of Visual Studio have included fxCop directly in the IDE, via the Code Analysis option. In previous versions of Visual Studio this just ran the fxCop command line and returned the results. There was not much else happening except a shortcut to having to run a separate tool.

In Visual Studio 2010 the fxCop integration has had a major improvement, with the addition of a dedicated interface for the management of what rules are run and the ability for you to create a bespoke collection of the rules that you care about by ignoring the rules you do not care about. The other great feature is that you can set if a rule throws a warning or an error in Visual Studio. Very useful for enforcing rules!

image

For Pull, I took the opportunity to create a dedicated rule set.

Step One – Theft

The first thing I did was to take the Microsoft All Rules rule set and copy it to my project and rename it to pull.ruleset. You can find the Microsoft All Rule rule set file at: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\Rule Sets\AllRules.ruleset

Step Two – Minor Tweak

Next I opened the pull.ruleset file in a text editor (it is just XML) and changed the rule set name and description.

image

Step Three – Associate

Next I used the Browse option in the rule set selector to select my pull.ruleset file.

Step Four – Adjust Rules

Now I can use the Visual Studio rules editor (click the Open button) to adjust what rules I want to keep and what severity level I want them at. As I started with the Microsoft All Rules, I have all the rules listed initially and so this took a little bit of time to adjust.

image

Step Five – Source Control

Make sure you check in your custom rule set file so that everyone in the team can enjoy it’s powerful magic. If I was using a fully featured ALM tool (like TFS) and not just a source control tool, then I could also include the rules in my check-in policies which ensure that code that is checked in comply and also in my build server.