Fork me on GitHub

StyleCop

StyleCop analyzes C# source code to enforce a set of style and consistency rules.

https://stylecop.codeplex.com

Install StyleCop

A good option to run StyleCop via command line is the StyleCopCmd project: https://github.com/inorton/StyleCopCmd

Download and put all files inside your project folder.

Run StyleCop

StyleCopCmd\Net.SF.StyleCopCmd.Console\StyleCopCmd.exe -sf .[Your Solution file].sln -of stylecop-report.xml

The report will be save to stylecop-report.xml

Generate StyleCop badge

BadgesSharpCmd -o [your GitHub username] -r [your GitHub repository] -a %GITHUB_REPO_TOKEN% -b StyleCop -c stylecop-report.xml

Show the badge at your GitHub repository

Edit your readme.md and add the line below:
![StyleCop](https://badgessharp.apphb.com/badges/:owner/:repo/StyleCop)

How use it on your Continuous Integration?

AppVeyor

Add to your AppVeyor.yml file:

after_build:
        - cmd: >
        StyleCopCmd\Net.SF.StyleCopCmd.Console\StyleCopCmd.exe -sf .[Your Solution file].sln -of stylecop-report.xml

        BadgesSharpCmd -o [your GitHub username] -r [your GitHub repository] -a %GITHUB_REPO_TOKEN% -b StyleCop -c stylecop-report.xml

TeamCity

Add the 'StyleCop' step to your configuration (probably you already have it);

Add a final 'Command Line' step to your configuration:

  1. Execute step: Even if some of the previous steps failed
  2. Run: Custom script
  3. Custom script:
    BadgesSharpCmd -o [your GitHub username] -r [your GitHub repository] -a %GITHUB_REPO_TOKEN% -b StyleCop -c "%system.teamcity.build.tempDir%\Stylecop-output-*\stylecop-result.xml"