I solved this by moving the VisualStudioTestPlatformInstaller
task before the SonarCloudPrepare
task.
After this change the Analysis output was:
Attempting to locate the CodeCoverage.exe tool...
VsTestToolsInstallerInstalledToolLocation environment variable detected, seeking for CodeCoverage.exe location...
VsTestToolsInstallerInstalledToolLocation environment variable doesn't contain full path to CodeCoverage.exe tool, seeking in standard place set by VSTestPlatformToolInstaller...
CodeCoverage.exe found at C:\agents\_work\_tool\VsTest\17.1.0\x64\tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe.
Code coverage command line tool: C:\agents\_work\_tool\VsTest\17.1.0\x64\tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
And coverage was displayed in SonarCloud.
More or less my .yaml
:
steps:
- task: VisualStudioTestPlatformInstaller@1
displayName: Install Visual Studio TestPlatform
inputs:
versionSelector: latestStable
- task: SonarCloudPrepare@1
displayName: Prepare SonarQube Analysis
inputs:
SonarCloud: SonarCloud
organization: xxx
scannerMode: MSBuild
projectKey: my_project
projectName: my/project
projectVersion: 1.0
extraProperties: |
sonar.exclusions=**/obj/**,**/*.dll,**/*.xml
sonar.cs.nunit.reportsPaths=$(Agent.TempDirectory)/*.trx
- task: DotNetCoreCLI@2
displayName: "dotnet restore"
inputs:
command: restore
projects: my/project
feedsToUse: config
nugetConfigPath: Nuget.Config
- task: DotNetCoreCLI@2
displayName: 'dotnet build'
inputs:
projects: my/project
arguments: '--configuration debug'
- task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: test
projects: my/testproject
arguments: --configuration debug /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx --results-directory $(Agent.TempDirectory) --collect "Code coverage" --no-build
- task: SonarCloudAnalyze@1
displayName: Run SonarQube Analysis
- task: SonarCloudPublish@1
displayName: Publish SonarQube Results
Coverage is then displayed in Azure Devops:
And in SonarCloud: