Geeks With Blogs

News

View Anthony Trudeau's profile on LinkedIn

Add to Technorati Favorites


Anthony Trudeau

Microsoft Visual Studio 2010 introduces the concept of rule sets when configuring code analysis.  This is a valuable change from Visual Studio 2008 that I didn't even realize I wanted.  Visual Studio 2008 by default selected all rules and then you had to remove rules on an item by item basis.

The rule sets fall into logical groups including "Microsoft All Rules", "Microsoft Basic Correctness Rules", "Microsoft Security Rules", et al.  And within the project properties you can select one rule set, multiple rule sets, or you can define your own rule set based upon another.

Selecting a single rule set is obviously the easiest option.  The default rule set when you create a new project is the "Microsoft Minimum Recommended Rules".  However, in my opinion the recommended rules are just too permissive.  For that reason you might want to change your rule set to "Microsoft All Rules" until you get around to creating your own rule set; or alternately you can select multiple rule sets which is an option from the rule set combo box.  The Visual Studio documentation has comprehensive help on what is contained within the rule sets.

Creating your own rule set is easy if not obvious.  You need to start a rule set from an existing rule set.  To get started select a rule set in the combo box within the Code Analysis tab of the project properties.  I selected the "Microsoft All Rules" for my rule set, but you may find it easier to start with the "Microsoft Minimum Recommended Rules" if your rules are on the more permissive side.

Once your rule set is selected click the Open button.  This will display a dialog that is similar in composition to the rules selection from Visual Studio 2008.  Browsing through the tree view you can select or deselect individual rules within their categories; and you can indicate that the rules are flagged as errors instead of the default which is a warning.  A nice touch to the form is that you get a help pane when you select an individual rule.  That helped me considerably when I first configured my rule set.

Once you have finished selecting your rules click the Save tool button, specify a location and name, and click the Save button on the Save As dialog.  Once you're back on the Code Analysis tab you'll choose the Browse option within the combo box and open the file you just created.

Posted on Tuesday, May 11, 2010 3:18 PM Visual Studio | Back to top


Comments on this post: Code Analysis Rule Sets in Visual Studio 2010

# re: Code Analysis Rule Sets in Visual Studio 2010
Requesting Gravatar...
Hi, my friend, your words help me a lot~
But I can't catch you up with this sentence: "To get started select a rule set in the combo box within the Code Analysis tab of the project properties. "
How can I get the combo box? I should describe my situation, so maybe you can help me.
I open source control setting dialogue box, switch to check-in policy tab, click Add button, select Code analysis, then I got the code analysis policy editor. I can select the rule set in a drop list, and there are some descriptions below it.
Can you tell me how can I find the combo box you mentioned, and how can I generate my own rule set?
Left by charlie on Mar 01, 2011 8:40 PM

# re: Code Analysis Rule Sets in Visual Studio 2010
Requesting Gravatar...
The option is available from the project properties.
Left by Anthony Trudeau on Mar 02, 2011 8:08 AM

# re: Code Analysis Rule Sets in Visual Studio 2010
Requesting Gravatar...
This is very great and brilliant information.
when to take a pregnancy test calculator
Left by jagu on Mar 24, 2018 5:33 AM

Your comment:
 (will show your gravatar)


Copyright © Anthony Trudeau | Powered by: GeeksWithBlogs.net