Generate code quality report using VSTS task

Posted by Anuraj on Wednesday, July 4, 2018 Reading time :1 minute

VSTS PowerShell

While implementing CI for one of the project, I implemented code quality check using Resharper Code Quality Analysis task. This task can fail the build, but this task will not generate a report. Since this task is internally using Inspectcode.exe, it will be able to generate the output XML file. In this post, I am writing a simple PowerShell script, which can be used as task, which will generate html report.

So first you need to include the Resharper Code Quality Analysis task in your build pipeline. I am using a Desktop application, so I am building the solution, copying the files to artifacts directory. Then I am running the code quality check.

Resharper Code Quality Analysis

By default this task won’t create the report xml file. So you need to configure it. You can do it by clicking on the task, select Advanced Options, and set the Results output file path property.

Resharper Code Quality Analysis - Advanced Options

Set it to $(Build.ArtifactStagingDirectory)\CodeQualityResults.xml.

Next you need to add a PowerShell task. Select the Inline type. And add following code in the Script textbox.

Write-Host "Generating the Code Quality Report"
    if (-NOT (Test-Path $DestinationFile)) {
    Write-Host "Report Generation - Missing file. Downloading from Github"
    wget "" -outfile  $DestinationFile
    $xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
Write-Host "Done."

So in this script, I am checking for a XSLT file in the artifacts directory and if not found downloading it from GitHub. Then I am loading the XSLT and transforming it to HTML using XslCompiledTransform object.

Here is the report is generated via this task.

Resharper Code Quality Analysis - Report

I have one more task added, which will send an email with report as attachment to the development team. You can do this using email notification tasks or using PowerShell.

Happy Programming :)

What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.

Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon

BMC logoBuy me a coffee

Copyright © 2019 - Anuraj P. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Hosted with ❤ by GitHub