Examples

The following example will call JetBrains InspectCode and output the number of warnings.

To call JetBrains InspectCode from a Cake script you need to add the JetBrains.ReSharper.CommandLineTools:

#tool "nuget:?package=JetBrains.ReSharper.CommandLineTools" // (1)!
  1. In production code this dependency should be pinned to a specific version to make sure builds are deterministic and won't break due to updates.

    See Reproducible Builds for details.

To read issues from InspectCode log files you need to import the core addin and the InspectCode support:

#addin nuget:?package=Cake.Issues&version=5.0.1
#addin nuget:?package=Cake.Issues.InspectCode&version=5.0.1

We need some global variables:

var logPath = @"c:\build\inspectcode.xml";
var repoRootPath = @"c:\repo";

The following task will run JetBrains InspectCode and write a log file:

Task("Analyze-Project").Does(() =>
{
    // Run InspectCode.
    var settings = new InspectCodeSettings() {
        OutputFile = logPath
    };

    InspectCode(repoRootPath.CombineWithFilePath("MySolution.sln"), settings);
});

Finally you can define a task where you call the core addin with the desired issue provider.

Task("Read-Issues")
    .IsDependentOn("Analyze-Project")
    .Does(() =>
    {
        // Read Issues.
        var issues =
            ReadIssues(
                InspectCodeIssuesFromFilePath(logPath),
                repoRootPath);

        Information("{0} issues are found.", issues.Count());
    });