Stylecop implementation for the CakeBuild build system.
C# PowerShell XSLT CSS JavaScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Cake.Stylecop
tools
.gitignore
Cake.Stylecop.sln
LICENSE.txt
README.MD
Settings.StyleCop
build.cake
build.ps1

README.MD

Cake.StyleCop

This is a thin wrapper around the standard StyleCop libraries which exposes StyleCop in a manner which can be used by Cake build scripts.

The .dlls included are available directly from The official StyleCop Project page

Note: Mis-reports some C#6 syntax as violations - this is due to the dll versions available. Once 4.7.55 is fully available from stylecop then this issue can be resolved.

#addin "Cake.StyleCop"

var target = Argument("target", "StyleCop");

Task("StyleCop")
  .Does(() =>
{
    // solution file
    var solutionFile = File("MySolution.sln");

    // stylecop settings file
    var settingsFile = File("Settings.stylecop");
    
    // xml results file
    var resultFile = File("StylecopResults.xml");

    // html report file
    var htmlFile = File("StylecopResults.html");

    StyleCopAnalyse(settings => settings
        .WithSolution(solutionFile)
        .WithSettings(settingsFile)
        .ToResultFile(resultFile)
        .ToHtmlReport(htmlFile)
    );
});

RunTarget(target);

Merging multiple stylecop result files

A second method is available if you need to merge several result files together to produce one report. This is useful for many CI servers

// html report file
var htmlFile = File("StylecopResults.html");

// reports 
var resultFiles = GetFiles("*.xml");

// will merge the xml files together before producing a single html file
StyleCopReport(settings => settings
    .ToHtmlReport(htmlFile)
    .AddResultFiles(resultFiles)
);

Customise the transform

There is a default xslt stylesheet which is used, but if you want to override this with your own, you can pass it to the settings in either method as follows

var xsltStyleSheet = GetFile("mystylesheet.xslt");

StyleCopAnalyse(settings => settings
  .ToHtmlReport(htmlFile, xsltStyleSheet)
);