When I run the sonar analysis on PR’s I see the following message in the coverage section of the Sonar report:
A few extra steps are needed for SonarCloud to analyze your code coverage Setup coverage analysis
I think that I have completed all of the steps in the link. What am I missing?
Here is my ymal file:
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
# Charles Teague November 22, 2023
trigger:
- main
- QA
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- checkout: self
fetchDepth: 0
- task: SonarCloudPrepare@1
inputs:
SonarCloud: 'SonarCloud LayoutBoards'
organization: '[Redacted]'
scannerMode: 'MSBuild'
projectKey: '[Redacted]'
projectName: '[Redacted]'
extraProperties: |
sonar.cs.xunit.reportsPaths=${Agent.TempDirectory}/**/XUnit.TestResults.xml
sonar.cs.opencover.reportsPaths=${Agent.TempDirectory}/**/opencoverCoverage.xml
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild@1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: ‘**/*Tests.csproj’
arguments: '--configuration $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=$(Agent.TempDirectory)/coverage/ /p:MergeWith=$(Agent.TempDirectory)/coverage/ --collect "Code coverage"'
- task: PublishTestResults@2
displayName: "Publish Test Results"
inputs:
testResultsFormat: VSTest
testResultsFiles: "$(Agent.TempDirectory)/**.*trx"
mergeTestResults: true
condition: succeededOrFailed()
- task: SonarCloudAnalyze@1
inputs:
jdkversion: 'JAVA_HOME_17_X64'
- task: SonarCloudPublish@1
inputs:
pollingTimeoutSec: '300'
Template for a good new topic, formatted with Markdown:
The above will not work without Visual Studio Enterprise addition. So, I switch to using Opencover and it worked great. I followed .NET Core Code Coverage done right – writeabout.net and modified its yml to work on my solution. This allow me to get coverage reports in Both Azure Dev opts and Sonar. Here is my yml: