OpenCover is not uploaded in Azure Devops

I’m trying to hook up my .Net Core & angular project in sonarcloud. I build and launch my tests using Azure Devops Yaml pipeline. Here is a summary of what’s happening.

First I have a Prepare analysis task :

  - task: SonarCloudPrepare@1
    displayName: 'Prepare analysis on Sonarcloud'
      SonarCloud: 'Sonarcloud'
      organization: ***redacted***
      scannerMode: 'MSBuild'
      projectKey: ***redacted***
      projectName: ***redacted***
      extraProperties: |

Then I build the project, everything is fine here. Then I launch the tests, and create a html report for my azure pipeline using report generator:

  - task: DotNetCoreCLI@2
    displayName: dotnet test
      command: test
      arguments: '--configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx'
      projects: 'Tests/**/*.csproj'
      nobuild: true

  - script: |
      dotnet tool install -g dotnet-reportgenerator-globaltool
      reportgenerator "-reports:$(Build.SourcesDirectory)/**/coverage.opencover.xml" "-targetdir:$(Build.SourcesDirectory)/CodeCoverage" "-reporttypes:HtmlInline_AzurePipelines;Cobertura"
    displayName: Create Code coverage report

  - task: PublishCodeCoverageResults@1
    displayName: 'Publish code coverage'
      codeCoverageTool: Cobertura
      summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml'
      reportDirectory: '$(Build.SourcesDirectory)/CodeCoverage'

Here again everything is fine, the tests run, the coverage is computed, the report is generated.

Then I install typescript (for sonar analysis) and I run the code analysis:

  - script: |
      cd $(Build.SourcesDirectory)/Src/***ProjectDir***
      npm install typescript
    displayName: 'Install typescript for sonar analysis'
  - task: SonarCloudAnalyze@1
    displayName: 'Run code analysis'
    continueOnError: false
  - task: SonarCloudPublish@1
    displayName: 'Publish code analysis'
    continueOnError: false
      pollingTimeoutSec: '300'

The sonar analysis finds the trx file but not the opencover coverage reports even though the path is provided in the sonar.cs.opencover.reportsPaths parameter in the prepare analysis task.

Here is the logs:

D:\a\_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.10.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 4.8
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.
17:31:43.118  Property 'sonar.cs.vstest.reportsPaths' provided, skipping the search for TRX files in default folders...
17:31:43.197  Did not find any binary coverage files in the expected location.
17:31:43.197  Falling back on locating coverage files in the agent temp directory.
17:31:43.197  Searching for coverage files in D:\a\_temp
17:31:43.243  No coverage files found in the agent temp directory.

Analysis is correctly uploaded on sonarcloud but the coverage shows 0%…
Any idea on how to solve this ?


Hi @NicolasC and welcome to the community !

The Scanner for MSBuild has an automatic detection of trx / coverage file, to be able to transform them into coveragexml files.

The rest of the supported coverages files (nunit, opencover, …) are being process directly by the subsequent analyzers, that’s the reason why you do not see any logs at first glance for those kind of files.

Can you share the full log of the Run Code Analysis task with debug mode enabled please ? I can send you a PM to do so. Let me know.


Ok my bad the coverage is in fact correctly reported.

The culprit was$(Build.SourceBranchName)
I didn’t have this option the first time I ran the build, and the coverage was not working, and the report was at the full branch name: folder/branch.
Then I added it with the other coverage parameters and this parameter strip the folder of the branch, so the new report with the coverage was in the branch (without the folder)

Then I was refreshing the report which was of course not updated.

Thanks for all.

1 Like