Merlijnv
(Merlijn Vermeer)
February 22, 2024, 11:40am
1
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
Merlijnv
(Merlijn Vermeer)
March 22, 2024, 7:59am
5
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.
ganncamp
(G Ann Campbell)
March 22, 2024, 12:05pm
8
Hi,
Could you describe how the current version is breaking your coverage?
Ann
Merlijnv
(Merlijn Vermeer)
March 22, 2024, 12:11pm
9
out of the sudden we where not getting coverage anymore
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.
ganncamp
(G Ann Campbell)
March 22, 2024, 4:08pm
10
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
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
Merlijnv
(Merlijn Vermeer)
March 28, 2024, 7:13am
11
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)
ganncamp
(G Ann Campbell)
March 28, 2024, 11:54am
12
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
Merlijnv
(Merlijn Vermeer)
March 28, 2024, 12:02pm
13
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.
ganncamp
(G Ann Campbell)
March 28, 2024, 12:58pm
14
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
Merlijnv
(Merlijn Vermeer)
March 28, 2024, 1:21pm
15
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:
Sorry for the inconvenience
ganncamp
(G Ann Campbell)
March 28, 2024, 3:50pm
16
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
Merlijnv
(Merlijn Vermeer)
April 3, 2024, 2:51pm
17
hmmm can only find vsts_fv-az363-173_2024-04-03.12_36_14.coverage in latest runs
Merlijnv
(Merlijn Vermeer)
April 4, 2024, 9:57am
18
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