Reputation: 25
Use of .Net Framework Application. I have tried to publish the code coverage result into Sonar Cloud Dashboard, but unable to publish the code coverage Report. Use of OpenCover.Console.exe + Vstest.console.exe
Please Refer the YAML File:
steps:
- checkout: self
clean: true
- task: NuGetToolInstaller@1
displayName: 'Use NuGet 4.x'
inputs:
versionSpec: 4.x
checkLatest: true
# Nuget restore for Service and presentation layer
- task: NuGetCommand@2
displayName: 'NuGet restore for service'
inputs:
restoreSolution: '${{ parameters.servicenugetSolution }}'
feedsToUse: config
nugetConfigPath: ${{ parameters.ServicenugetPath }}
condition: and(succeeded(), or(eq('${{ parameters.Service }}', 'true'), eq('${{ parameters.ServiceandPresentation }}', 'true')) )
- task: NuGetCommand@2
displayName: 'NuGet restore for Presentation'
inputs:
restoreSolution: ${{ parameters.presentationSolution }}
feedsToUse: config
nugetConfigPath: ${{ parameters.presentationnugetPath }}
condition: and(succeeded(), or(eq('${{ parameters.Presentation }}', 'true'), eq('${{ parameters.ServiceandPresentation }}', 'true')) )
- task: NuGetCommand@2
displayName: 'NuGet restore for Solution'
inputs:
restoreSolution: '**/*.sln'
feedsToUse: config
nugetConfigPath: ${{ parameters.presentationnugetPath }}
condition: and(succeeded(), eq('${{ parameters.nugetRestoreAllSolutions }}', 'yes'))
# Sonar cloud for Service and presentation layer
- task: SonarSource.sonarcloud.14d9cde6-c1da-4d55-aa01-2965cd301255.SonarCloudPrepare@1
displayName: 'Prepare analysis on SonarCloud'
condition: and(succeeded(), ne('${{ parameters.SonarProjectKey }}', ''), or(eq('${{ parameters.Presentation }}', 'true'), eq('${{ parameters.Service }}', 'true'), eq('${{ parameters.ServiceandPresentation }}', 'true')))
inputs:
SonarCloud: SonarCloud
organization: msc
projectKey: ${{ parameters.SonarProjectKey }}
projectName: ${{ parameters.SonarProjectName }}
extraProperties: |
sonar.exclusions=${{ parameters.SonarExclusions }}
sonar.dotnet.excludeTestProjects=true
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/CoverageResults.xml
# Service Solution Build
- task: VSBuild@1
displayName: 'Build solution ${{ parameters.serviceSolution }}'
inputs:
solution: ${{ parameters.serviceSolution }}
msbuildArgs: '/p:OutDir=$(Build.BinariesDirectory)/Service /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
clean: true
msbuildArchitecture: x64
logProjectEvents: false
maximumCpuCount: true
vsVersion: ${{ parameters.VsVersion }}
condition: and(succeeded(), or(eq('${{ parameters.Service }}', 'true'), eq('${{ parameters.ServiceandPresentation }}', 'true')) )
# Presentation Solution Build
- task: VSBuild@1
displayName: 'Build solution ${{ parameters.presentationSolution }}'
inputs:
solution: ${{ parameters.presentationSolution }}
msbuildArgs: '/p:OutDir=$(Build.BinariesDirectory)/Presentation'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
clean: true
msbuildArchitecture: x64
logProjectEvents: false
maximumCpuCount: true
vsVersion: ${{ parameters.VsVersion }}
condition: and(succeeded(), or(eq('${{ parameters.Presentation }}', 'true'), eq('${{ parameters.ServiceandPresentation }}', 'true')) )
- task: PowerShell@2
displayName: 'Execute Code Coverage'
inputs:
targetType: 'inline'
script: |
get-location
Echo "LocationPath:" $(Build.BinariesDirectory)
Set-Location -Path $(Build.BinariesDirectory)
$getSrcdirectory = "$(Build.SourcesDirectory)"
$OpenCover = "E:\Software\opencover.4.7.1221\OpenCover.Console.exe"
$ReportGenerator = "$(Build.BinariesDirectory)\reportgenerator.exe"
&$OpenCover -register:user -target:"vstest.console.exe" -targetargs:".\service\SampleWork.Api.Test.dll" -output:"$($getSrcdirectory)\CoverageResults.xml"
# Run Code Analysis &Publish Quality Gate Result
- task: SonarSource.sonarcloud.ce096e50-6155-4de8-8800-4221aaeed4a1.SonarCloudAnalyze@1
displayName: 'Run Code Analysis'
condition: and(succeeded(), or(eq('${{ parameters.Presentation }}', 'true'), eq('${{ parameters.Service }}', 'true'), eq('${{ parameters.ServiceandPresentation }}', 'true')) )
I have try to trigger on YAML Pipeline it was working fine. The task execution details are..
Final Report Is: Code Coverage report was not publish in Sonar Cloud Dashboard
Question Is: Use of OpenConsole.exe and Vstest.console.exe to Publish the Code Coverage Result into Dashboard
Upvotes: 0
Views: 112