Sunday 4 October 2009

C# Code Analysis Tools

StyleCop:
StyleCop is a free static code analysis tool from Microsoft that checks C# code for conformance to StyleCop's recommended coding styles and a subset of Microsoft's .NET Framework Design Guidelines such as casing, white space, indents, etc.

It can be run from inside of Visual Studio or integrated into an MSBuild project.

Links:
FxCop:
FxCop is a free static code analysis tool from Microsoft that checks .NET managed code assemblies for conformance to Microsoft's .NET Framework Design Guidelines.

It's main concerns are:
  • Correctness
  • Library design
  • Localization
  • Naming conventions
  • Performance
  • Security
Unlike StyleCop, you can't run FxCop from inside Visual Studio but it has a project for itself that needs to be opened.


Tip: Both FxCop and StyleCop have few overlapping features such as Naming Convention

Visual Studio Integration Code Analysis Tool:
FxCop is essentially a standalone version of Visual Studio Integration Code Analysis.

NArrange

Resharper:

1 comment:

Best Guitar said...

Very helpful blog on c# code analysis tools which is in very easy language. However, FxCop also helps in checking lots of issue with the Microsoft Guidelines. Some of the more interesting issues that are checked for:

1. Are reference parameters of methods checked to be non-null before use?
2. Are fields initialized to default values that are already assigned by the runtime, like null for reference fields?
3. This would result in an unnecessary extra assignment.
4. Does the string argument to Argument Out Of Range Exception contain the name of the argument?