BT

InfoQ Homepage News Custom Code Analysis in Visual Studio 2010

Custom Code Analysis in Visual Studio 2010

Bookmarks

Microsoft’s .NET code analysis tool, FXCop, has offered the ability to create custom code analysis rules for many years, but the experience has been less than stellar. The version for VS 2010 offers some improvements and a better integration story, but some fundamental problems still remain.

Up front there is something you need to know about .NET code analysis; there is no SDK. Microsoft fully reserves the right to change any aspect of the FXCop API at any time. This means any custom rules you write for VS 2010 may need to be modified or outright rewritten when VS 11 comes out a few years from now. This also means that there is little documentation outside blogs and newsgroups.

There are also no plans to release any of the built-in code analysis rules under a open or shared source license. So all the custom rules you write need to be written from scratch even if a built in one almost does what you want. Since code analysis is a hot topic in Computer Science research and a major selling point for Visual Studio Premium edition, this isn’t likely to change anytime soon.

If you are still interested, the development experience isn’t too bad. Simply inherit from BaseIntrospectionRule, override the methods you care about, and add a matching XML-base meta-data file. Duke Kamstra, Program Manager for Microsoft, has a walk-through on his Code Analysis and Code Metrics blog.

Long-time custom rule writers will note that the procedure has changed significantly from VS 2008. This was done to support the new rule sets feature, which allows one to easily apply and maintain the same rules across multiple projects.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.