Fxcop and Stylecop : How to improve quality of code



StyleCop:


  •  StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. StyleCop has also been integrated into many third-party development tools.
  •  Those who are using Resharper, resharper in turn using stylecop.  Stylecop works on the code we write and we can check for coding guidelines followed. Stylecop or Reshaper uses MSDN coding guidelines by default but we can write our custom rules.
  • We can select the rules we want to apply by stylecop settings. Stylecop settings generate files which contains which are all rules to be avoided. 
  • We can also integrate the stylecop in build and unlike resharper which doesn’t show detailed errors, we can get the below. But resharper and stylecop we use should match.
  • We can introduce the stylecop checkin rules in SVN but it is for entire file not delta changes.

Fxcop : 


  • Unlike Stylecop, Fxcop works on managed assemblies instead of code.
  • Refer below link to find difference between stylecop and fxcop.
  • Mangaging Fxcop :
  • We can integrate fxcop into Visual studio. Here is the link.
  • We can add custom rules to the FXcop. Refer below link :
  •  While analyzing Strong name assemblies or any assembly with reference assemblies, then we can ignore the referenced assemblies or can search for GAC for references.
http://stackoverflow.com/questions/12275570/fxcop-cant-resolve-references
  • In Visual studio 2010 Fxcop is integrated in Code Analysis. In vs 2008 it is not there.
  • We can set the rules in code analysis tab.

Best practices :

We are using only coding guidelines but there are best practices of writing C# code like usage of string.empty instead of “”.  restricting the class size etc.

Even code analysis we can do it in visual studio.

No comments:

Post a Comment

Pages