Monday, June 27, 2011

StyleCop Tutorials

StyleCop is a tool that analyzes C# source code to enforce a set of style and consistency rules. It can directly work from Visual Studio 2010. Also as compared to FxCop it works with source code not with compiled assemblies. It will verify against the rules provided by microsoft towards coding, design ect. standards.
You can download the latest vesion from here.
Once download completes install it. Then open Visual Studion 2010, It will appear under
Tools menu as shown below.

To run it, You can go to Tools -> Run StyleCop, It will display you warnings in the Error List window like below.
Here SA1005, SA1006 etc are the error code, then it displays the cause of the error, then the file name (Class1), in line number etc.

You can also change the Setting in the project level. Right click on the project -> click on StyleCop Settings, it will appear as shown below.

There you can navigate to the Rules tab and you can select/deselect the rules as shown in the below figure. After that StyleCop will only verify for the rules you have selected.