1

I have created a build pipeline in Azure DevOps for one of my ASP.NET MVC application. There exist projects for unit testing, and I need to generate code coverage report, for which I have used coverlet.msbuild NuGet package, and "ReportGenerator".

Following is the packages.config file of one of the unit test project:

<packages>
  <package id="coverlet.msbuild" version="2.8.0" targetFramework="net461" developmentDependency="true" />
  <package id="NUnit" version="2.6.3" targetFramework="net45" />
  <package id="ReportGenerator" version="4.4.6" targetFramework="net461" />
</packages>

Also, please find the yaml of Build solution, test assemblies, and ReportGenerator tasks in build pipeline:

Build Solution:

steps:
- task: VSBuild@1
  displayName: 'Build solution **\SmartStoreNET.sln'
  inputs:
    solution: '**\SmartStoreNET.sln'
    msbuildArgs: '/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura'

Test Assemblies

steps:
- task: VSTest@2
  displayName: 'Test Assemblies'
  inputs:
    testAssemblyVer2: |
     **\$(BuildConfiguration)\*test*.dll
     !**\obj\**
    codeCoverageEnabled: true
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

ReportGenerator

steps:
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
  displayName: ReportGenerator
  inputs:
    reports: '$(Build.SourcesDirectory)/tests/**/coverage.cobertura.xml'
    targetdir: '$(Build.SourcesDirectory)/CodeCoverage'
    reporttypes: 'HtmlInline_AzurePipelines;Cobertura;Badges'

While executing the pipeline I am getting following error in ReportGenerator task:

The report file pattern 'd:\a\1\s/tests/**/coverage.cobertura.xml' is invalid. No matching files found.

Can anyone please suggest what is missing here, or what could be the potential issue.

Any help on this would be much appreciated.

Thanks,

Nirman

Nirman
  • 6,715
  • 19
  • 72
  • 139
  • Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance. – Leo Liu Feb 07 '20 at 13:18

1 Answers1

3

Unable to generate code coverage report using ReportGenerator

AFAIK, the properties /p:CollectCoverage=true and /p:CoverletOutputFormat=cobertura are used for the test task to generate coverage results not for the build task.

But there is an issue for getting coverlet to run using the Visual Studio Test task, so that we could not use above properties for the VS test task directly.

As workaround, you could try to install the tool during the pipeline and then generate the report with powershell scripts:

dotnet tool install dotnet-reportgenerator --tool-path . --version 4.0.12
dotnet tool install coverlet.console --tool-path . --version 1.4.1
mkdir .\reports
$unitTestFile = gci -Recurse | ?{ $_.FullName -like "*bin\*test*.dll" }
$coverlet = "$pwd\coverlet.exe"
& $coverlet $unitTestFile.FullName --target "dotnet" --targetargs "vstest $($unitTestFile.FullName) --logger:trx" --format "cobertura"
gci -Recurse |
?{ $_.Name -eq "coverage.cobertura.xml"} |
%{ &"$pwd\reportgenerator.exe" "-reports:$($_.FullName)" "-targetdir:reports" "-reportstypes:HTMLInline;HTMLChart" }

Check the this thread and the document for some more details.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Sorry for getting late on this. I could try it today only and getting following error - "error NU1101: Unable to find package dotnet-reportgenerator. No packages exist with this id in source(s): C:\Program Files\dotnet\sdk\NuGetFallbackFolder, Microsoft Visual Studio Offline Packages, nuget.org" – Nirman Apr 06 '20 at 14:08