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

1
  • Just checking in to see if the information provided was helpful. Please let us know if you would like further assistance. Commented Feb 7, 2020 at 13:18

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.