Battling some of the errors generated by Microsoft Source Analysis for C#

by Tobias Hertkorn on May 24th, 2008

AssemblyInfo.cs

If you want to get rid of all the errors related to AssemblyInfo.cs and as a matter of fact any other autogenerate file use the autogenerated tag at the beginning of the file like so:

XML:
  1. //<autogenerated />

How to format the file header

SA1633 calls for a valid header XML. If you are curious how to format the required file header here is an example:

XML:
  1. // <copyright file="Program.cs" company="My Company">
  2. //     Copyright (c) Tobias Hertkorn. All rights reserved.
  3. // </copyright>

kick it on DotNetKicks.com

Post to Twitter Tweet this

May 24th, 2008 6:30 pm | Comments (3)

Writing your own rules for Microsoft Source Analysis for C#

by Tobias Hertkorn on May 24th, 2008

Marcelo announced the release of the Microsoft Source Analysis for C# over at MSDN Code Gallery. Quoting from the newly formed blog specially dedicated to that tool:

This tool is known internally within Microsoft as StyleCop, and has been used for many years now to help teams enforce a common set of best practices for layout, readability, maintainability, and documentation of C# source code.

I am always looking for a way to improve my coding style and I was hoping to find out more about what the Microsoft coding style looks like. And I was fortunate: The tool actually ships with a lot of baked in rules ... which I would be happy to comply to, if I could just find out how to comply to them. :) So I set out to find out how that tool works - and how to tweak and adjust the build in sets. Hint: Installation directory is "%ProgramFiles%/Microsoft Source Analysis Tool for C#".

What the tool basically does is:

  1. find all files in the current solution
  2. Create a parse tree of any given file
  3. load all dlls in installation folder and find all classes derived from Microsoft.SourceAnalysis.SourceAnalyzer
  4. Execute each analyzer
  5. Report

To find out more about the rules that ship with Source Analysis (loaded in step 3) on has to look at the assembly Microsoft.SourceAnalysis.CSharp.Rules.dll.
The ones baked in are specifically:

  • DocumentationRules
  • LayoutRules
  • MaintainabilityRules
  • NamingRules
  • OrderingRules
  • ReadabilityRules
  • SpacingRules

And if you want to replace them with your own custom set, all you have to do is delete that particular dll - and design your own set. The code is very well structured, so it should not too hard to find your way around using Reflector. Enjoy.

kick it on DotNetKicks.com

Post to Twitter Tweet this

May 24th, 2008 3:00 pm | Comments (4)
Tobi + C# = T# - Blogged blogoscoop