Fun with Code Analysis Rule Sets

Two weeks ago, I introduced you to Visual Studio 2010 September ’08 CTP (Community Technology Preview). This CTP is available as a Virtual PC (VPC) image which can be downloaded at http://go.microsoft.com/fwlink/?LinkId=129231. The goal of the Community Technology Preview is to obtain feedback from our customers on the new scenarios we have enabled.  If you…

5

Tutorial on writing your own Code Analysis rule

Jason Kresowaty has posted a great tutorial on writing Code Analysis/FxCop rules. He also spends time on explaining parts of the Introspection API, including the different nodes and their relationship to each other. It’s a great read, even if you’ve written some Code Analysis rules before. Definitely recommended.

4

What kind of custom rules do you want to write?

Our excellent program manager, Joe Rohde, is trying to gather information on the kinds of custom rules customers want to write. I am a program manager for our Code Analysis system. I want to know what kind of custom rules you would like to write. Ignore what you may or may not know about what’s in FxCop…

8

FAQ: How do I debug a custom rule?

While writing your custom rule, you will likely come across a need to debug it and work out why it’s behaving in a particular manner.Debugging within FxCop  Debugging a custom rule within the FxCop UI is actually quite easy. To do so, simply: Open the FxCop project that contains your custom rule (making sure the PDB…

3

Dealing with a Code Analysis backlog?

Nicole Calinoiu has started a (what I hope to be long) series on introducing Code Analysis (FxCop in particular) to your team. Her first couple of posts are absolute rippers, check them out: FxCop and the big, bad backlogFxCop backlogs: Some rules for rule activation She’s also written some custom rules content: No rules in…

1

FAQ: How do I get the SourceContext for a local?

I want to fire on the naming of a local, however, whenever I pass the local to the Problem constructor, the source information for the method is always used. How do I get FxCop/Code Analysis to use the source information for the local instead? Because the declaration of a local is not associated with an executable instruction, a…

5

Framework for intergrated FxCop rule testing

Roy Osherove has put together a Framework for testing FxCop rules. It’s an interesting approach, firing up the FxCop engine for each rule that he wants to test. There are few things that I would like to see it support: The ability to specify positive tests (code that rules should not fire when run over)…

6

FAQ: When looking at the names of locals in a custom rule, why do I see strange names such as ‘CS$1$0000’ and ‘VB$1$0000’?

Previously we showed you how to access the locals or variables of a method. Once you started to run your rule over an assembly, you might start to notice strange locals with names that start with ‘CS$’ and ‘VB$’. These are compiler generated locals that are outside the control of the user. If you are…


Free sample book chapter on Managed Code Analysis

SearchVB.com is offering  a free sample chapter on Managed Code Analysis from the book Professional Visual Studio Team System (co-written by fellow Team System colleague Noah Coad). Chapter 8, Managed Code Analysis, focuses on how to use Team System’s Static Code Analysis tool for C# or VB.NET code. This tool checks code for adherence to Microsoft’s…

1

FAQ: Can I create custom rules that target both Visual Studio and FxCop? [David Kean]

I have users using both Visual Studio and FxCop, and I want to create custom rules that run on both. Is this possible? Although in the future we do plan on making it easier to move custom rules between Visual Studio and FxCop, currently you must recompile each rule assembly against the version of FxCop/Visual…

5