SonarCloud Azure DevOps extension MSBuild reporter v 5.14

I’d like to bring up an issue regarding the SonarCloud Azure DevOps extension. It appears that the extension is still using MSBuild reporter version 5.14, and there hasn’t been an update on the extension since October 18, 2023.

This is causing problems for us as it hinders the proper reading of our .NET Core code coverage in opencoverage format. Could you please provide information on the reasons behind the delay in updating the MSBuild reporter and how it might be impacting the extension’s functionality?

Assistance in this matter is much appreciated.

Hello @Merlijnv ,

Apologies for the delay of the response,

The latest extension for SonarCloud embeds version 5.15 of the MSBuild scanner. We have an internal task [VSTS-356] - Jira to integrate the version 6 of the MSBuild scanner. This effort is not planned yet but you can follow its progress in the ticket.

Hope this answer helps

Hello benjamin,

Why is this effort not planned yet if it is breaking code coverage on sonarcloud?
We don’t get any code coverage besides the one in azure devops itself.

Hi,

Could you describe how the current version is breaking your coverage?

 
Ann

out of the sudden we where not getting coverage anymore
image

We are using the following steps:

steps:
  - task: SonarCloudPrepare@1
    displayName: Prepare SonarCloud
    enabled: ${{ parameters.buildWithAllTesting }}
    inputs:
      SonarCloud: "SonarCloud Service Connection"
      organization: "rsr"
      scannerMode: "MSBuild"
      projectKey: ${{ parameters.projectKey }}
      projectName: ${{ parameters.projectName }}
      projectVersion: $(BuildVersion)
      extraProperties: |
        sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/*.opencover.xml
        sonar.project.monorepo.enabled
  - task: DotNetCoreCLI@2
    displayName: Test
    ${{ if eq(parameters.artifactName, 'TranslinkAcl') }}:
      env:
        MONGO_CONNECTION_STRING: $(MONGO_CONNECTION_STRING)
    enabled: ${{ parameters.buildWithAllTesting }}
    inputs:
      command: test
      projects: "**/${{ parameters.solutionFile }}"
      arguments: '--configuration ${{ parameters.buildConfiguration }} --collect "Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
  - task: PublishCodeCoverageResults@2
    displayName: 'Publish Code Coverage'
    inputs:
      summaryFileLocation: '$(Agent.TempDirectory)/**/*.coverage'
      failIfCoverageEmpty: true
  - task: SonarCloudAnalyze@1
    displayName: Analyze with SonarCloud
    enabled: ${{ parameters.buildWithAllTesting }}

  - task: SonarCloudPublish@1
    displayName: Publish with SonarCloud
    enabled: ${{ parameters.buildWithAllTesting }}
    inputs:
      pollingTimeoutSec: "300"

The PublishCodeCoverageResults step is working and the coverage is being generated but sonarcloud is not receiving it anymore.
When looking into it we taught msbuild reporter having an old version was the problem.
But maybe you find something else looking into it.

Hi,

Thanks for the pipeline.

I’m not seeing the actual build step in here?

Also could you provide a verbose analysis log?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Ann

Hey Ann,

Sorry for the late response I didn’t add the build and restore step didn’t think that was necessary.

steps:
  - task: SonarCloudPrepare@1
    displayName: Prepare SonarCloud
    enabled: ${{ parameters.buildWithAllTesting }}
    inputs:
      SonarCloud: "SonarCloud Service Connection"
      organization: "rsr"
      scannerMode: "MSBuild"
      projectKey: ${{ parameters.projectKey }}
      projectName: ${{ parameters.projectName }}
      projectVersion: $(BuildVersion)
      extraProperties: |
        sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/*.opencover.xml
        sonar.project.monorepo.enabled
  - task: Cache@2
    displayName: Cache nuget packages
    enabled: false
    inputs:
      key: 'nuget | "$(Agent.OS)" | **/packages.lock.json,!**/bin/**,!**/obj/**,!**/microservice/**'
      restoreKeys: |
        nuget | "$(Agent.OS)"
        nuget
      path: "$(Pipeline.Workspace)/.nuget/packages"
      cacheHitVar: "CACHE_RESTORED"

  - task: DotNetCoreCLI@2
    displayName: Restore
    enabled: false
    inputs:
      command: "restore"
      projects: "**/${{ parameters.solutionFile }}"
      restoreDirectory: "$(Pipeline.Workspace)/.nuget/packages"

  - task: DotNetCoreCLI@2
    displayName: Build
    inputs:
      command: "build"
      projects: "**/${{ parameters.solutionFile }}"
      arguments: "-v:d --configuration release /p:DebugType=None /p:Version=$(BuildVersion) /p:AssemblyVersion=$(GitVersion.MajorMinorPatch)"
  - task: DotNetCoreCLI@2
    displayName: Test
    enabled: ${{ parameters.buildWithAllTesting }}
    inputs:
      command: test
      projects: "**/${{ parameters.solutionFile }}"
      arguments: '--configuration ${{ parameters.buildConfiguration }} --collect "Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover'
  - task: PublishCodeCoverageResults@2
    displayName: 'Publish Code Coverage'
    inputs:
      summaryFileLocation: '$(Agent.TempDirectory)/**/*.coverage'
      failIfCoverageEmpty: true
  - task: SonarCloudAnalyze@1
    displayName: Analyze with SonarCloud
    enabled: ${{ parameters.buildWithAllTesting }}

  - task: SonarCloudPublish@1
    displayName: Publish with SonarCloud
    enabled: ${{ parameters.buildWithAllTesting }}
    inputs:
      pollingTimeoutSec: "300"

for verbose logging
msbuild log:
sonarbuildlog.txt (8.1 MB)

test log:
sonartestlog.txt (20.4 KB)

sonaranalysis log:
sonaranalysislog.txt (2.3 MB)

Hi,

How many projects are there in your solution? Because your analysis log has 12 instance of this:

Excluded sources for coverage: **/*

Somewhere you have a global coverage exclusion set. I don’t see it in your pipeline, but there are multiple places it could be set.

 
Ann

Hey Ann,

In this solution there are 7 projects (all the same application but broken op in core, infratstructure, persistence and webapi).
I think the coverage exlcusions you are seeing are the shared code because not alle shared code will be covered when running analysis for this application.

Hi,

You have 7 projects, and 12 incidences of the exclusion in your log. I suppose that covers the projects and the shared code…

 
Ann

Hey Ann,

Sorry I made a mistake.
I picked logs of the application that isn’t a problem if logs and such are shared but apperently there is a */ exlcude coverage for that project in sonar because we don’t care about the coverage for that specific project. The other projects don’t have the same exclude.
I deleted the exclude and reran the pipeline.
Here are the logs where exclusion of coverage on this project is nog all ignored.
msbuild log:
sonarbuildlog.txt (8.2 MB)

test log:
sonartestlog.txt (20.4 KB)

sonaranalysis log:
sonaranalysislog.txt (2.5 MB)

Also coverage in azure devops is working as shown below for this run:


But no in sonarcloud:
image

Sorry for the inconvenience

Hi,

Thanks for the new logs. I see this:

2024-03-28T13:18:15.5108139Z 13:18:15.510 INFO: Sensor C# Tests Coverage Report Import [csharp]
2024-03-28T13:18:15.5119018Z 13:18:15.511 DEBUG: Analyzing coverage with wildcardPatternFileProvider with base dir '/home/vsts/work/1/.' and file separator '/'.
2024-03-28T13:18:15.5130041Z 13:18:15.512 DEBUG: Pattern matcher extracted prefix/absolute path '/home/vsts/work/_temp' from the given pattern '/home/vsts/work/_temp/**/*.opencover.xml'.
2024-03-28T13:18:15.5172237Z 13:18:15.517 DEBUG: Gathering files for wildcardPattern '**/*.opencover.xml'.
2024-03-28T13:18:15.6931741Z 13:18:15.692 DEBUG: Pattern matcher returns '0' files.
2024-03-28T13:18:15.6940472Z 13:18:15.693 WARN: Could not find any coverage report file matching the pattern '/home/vsts/work/_temp/**/*.opencover.xml'. Troubleshooting guide: https://community.sonarsource.com/t/37151
2024-03-28T13:18:15.6952350Z 13:18:15.695 DEBUG: Analyzing coverage after aggregate found '0' coverage files.
2024-03-28T13:18:15.6959190Z 13:18:15.695 DEBUG: The total number of file count statistics is '0'.
2024-03-28T13:18:15.6959820Z 13:18:15.695 INFO: Sensor C# Tests Coverage Report Import [csharp] (done) | time=185ms

Can you verify that a *.opencover.xml file exists in the workspace during analysis?

 
Thx,
Ann

hmmm can only find vsts_fv-az363-173_2024-04-03.12_36_14.coverage in latest runs

Fixed the coverage by using
sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/coverage.opencover.xml
In Prepare and
–collect:“XPlat Code Coverage” – DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura,opencover
In test

1 Like