BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Custom Code Analysis in Visual Studio 2010

| by Jonathan Allen Follow 133 Followers on Apr 03, 2010. Estimated reading time: 1 minute |

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 Stage
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.

Tell us what you think

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

Email me replies to any of my messages in this thread
Community comments

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

Email me replies to any of my messages in this thread

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

Email me replies to any of my messages in this thread

Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT