Friday, June 14, 2013

Integrating StyleCop with MSBuild

How to use StyleCop

StyleCop is an open source static code analysis tool from microsoft which is used to maintain coding standards for the c# code

Download style cop from this url
Step2 Install it in MSBuild Mode as show below

sample project to test style cop

Follow the slides initially

Now run the project it won’t show any warning ,we have run style cop manually .

We can integrate this process to MSBuild by adding tag in ‘.csproj ‘ file.

To do that we have unload project first then open “csproj” file to include those tags.

Edit csproj file

Copy the path of the file styleCop.Targets

Include that stylecop.Targets path in import tag in csproj file

Now save changes and reload the project. Now buid /run solution , you find warnings on fly as shown below

To show those warnings as errors add following tag to csproject file as shown below in the rounded code

Save and reload project . Now run/build project . you will see following screen

No comments:

Post a Comment