Microsoft Source Analysis for C#

Microsoft announce the public release of a new developer tool –ย  Source Analysis for C#.

Inside Microsoft this tool’s name is StyleCop and it enforces code style guidelines on the code we write

Source Analysis comes with a set of default rules analyzers covering approximately 200 best practice rules. These rules are full compatible with the default layout settings in Visual Studio 2005 and Visual Studio 2008.

Specifically, these rules cover the following, in no particular order:

  • Layout of elements, statements, expressions, and query clauses
  • Placement of curly brackets, parenthesis, square brackets, etc
  • Spacing around keywords and operator symbols
  • Line spacing
  • Placement of method parameters within method declarations or method calls
  • Standard ordering of elements within a class
  • Formatting of documentation within element headers and file headers
  • Naming of elements, fields and variables
  • Use of the built-in types
  • Use of access modifiers
  • Allowed contents of files
  • Debugging text

After installation, Source Analysis can be run from within the Visual Studio IDE. You can set this up to be run as a part of your build process as documented here. Since this is plugged in as a MsBuild project you can use it in as a part of Team Foundation Build process as well.

Running Source Analysis:


And the results are:


Download it from:

Read full details:

NDepend – Great Static Analyzer

Few week ago, I’ve been asked by Patrick Smacchia, a C# MVP to try this tool. I really want to thanks Patrick to give me the chance to evaluate a professional edition.

I installed it and start working with. After using this tool, it’s my most favorite tool to reviewing my code!

NDepend is an excellent tool that is designed to provide a very deep analysis of your compiled code to help you understand and control your development effort by managing both the quality and the complexity of your code. NDepend works in a very similar way as the Microsoft FxCop tool, by analyzing your compiled code and calculating different metrics and statistics on that code.

NDepend analyzes your code against more than 60 different metrics and can be customized to a particular application. These metrics measure things like:

  • Lines of Code, Comments and the percentage of comments
  • Number of IL instructions
  • Number of Assemblies, Namespaces, Types, Methods, Fields
  • Coupling (both Afferent and Efferent), Cohesion and Cyclomatic Complexity
  • Instability
  • Abstractness
  • Depth of Inheritance

NDepend’s start page:

Start Page

NDepend’s analyzing result and projects loaded:

Analyzing Result

A great feature is the NDepend’s CQL (Code Query Language). It is the one of its main features that I love.ย  It’s a query language for code so one can issue statements like:


Its great to query your code this way, besides we’re all familiar with T-SQL… ๐Ÿ™‚

Visual NDepend also has this metrics view which graphically represents any criteria from number of lines of code such as represented below, to number of methods, parameters, coupling, etc.ย  The bigger the square below means more number of lines of code.

Another feature for the professional edition (not available in the free edition) is the build comparisons.ย  It basically analyzes two build versions, analyze what’s been deprecated, broken, etc.ย  It’s useful to easily know if an upgrade to a component you’re using will break your app.ย  It also provides easy access on the details of what has been changed.

The binaries also include extensions for MSBuild, NAnt and CruiseControl.NET so you can readily include NDepend tasks in your build scripts for your continuous integration setup.

NDepend is great for architects or even team leads who wants to have a quick overview of their project rather than diving into the code and scratch their heads.

Addins of NDepends available to VS2008, VS2005 and Reflector.

NDepends web site:

Code Analysis in VS 2008

VS 2005 introduced internal static analysis tools. This helps you to write secure and quality code.

Visual Studio 2008 has new Code Analysis features:

  • Code Metrics – This gives you the ability to dig deep to find those un-maintainable and complex hotspots. Code Metrics will ship with five metrics – Cyclomatic Complexity, Depth of Inheritance, Class Coupling, Lines of Code and Maintainability Index.
  • Analysis improvements:
    • Support for analyzing anonymous methods and lambda expressions
    • Reduced noise in existing analysis and the ability to skip over tool generated code
    • New analysis, including additional rules around security, globalization, maintainability and spelling.

To generate code metrics, simply do the following:In Solution Explorer, right-click on your solution/project and choose Generate Code Metrics


After generation you’ll get the Code Metrics Results window and a tooltip on every column that explain the result. The Maintainability Index column includes a maintainability indicator light that changes based on the maintainability of the code. Green indicates good maintainability, yellow indicates moderate maintainability, and red indicates poor maintainability.


Technorati Tags: ,
%d bloggers like this: