BT

Custom Code Analysis in Visual Studio 2010

by Jonathan Allen on Apr 03, 2010 |

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.

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

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT