Code Coverage is always showing as 0%

  • ALM used - Azure DevOps
  • CI system used Azure DevOps
  • Scanner command used when applicable (private details masked

Sonar tasks in yml as below

  • task: SonarCloudPrepare@1
    SonarCloud: ( organization: (Sonar.organization)
    scannerMode: (Sonar.scannerMode) projectKey: (Sonar.cliProjectKey)
    projectName: (Sonar.cliProjectName) extraProperties: | sonar.cs.opencover.reportsPaths=(Build.SourcesDirectory)/**/coverage.opencover.xml
    • task: VSBuild@1
      solution: ‘**/*.sln’
      msbuildArgs: ‘/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="(build.artifactStagingDirectory)\" /p:DeployIisAppPath="Default Web Site"' platform: '(MSBuild.buildPlatform)’
      configuration: ‘$(MSBuild.buildConfiguration)’

    • task: VSTest@2
      platform: ‘(MSBuild.buildPlatform)' configuration: '(MSBuild.buildConfiguration)’

    • task: VSTest@2
      displayName: Sonartest
      command: test
      projects: ‘**/Gac.Integration.RoutingEngine.Tests/Gac.Integration.RoutingEngine.Tests.csproj’
      arguments: ‘/p:CollectCoverage=true /p:CoverletOutputFormat=opencover --logger trx’
      configuration: ‘$(MSBuild.buildConfiguration)’

    • task: SonarCloudAnalyze@1

    • task: SonarCloudPublish@1
      pollingTimeoutSec: ‘300’

  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)

Attempting to locate the CodeCoverage.exe tool…

Attempting to locate the CodeCoverage.exe tool using setup configuration…

Code coverage command line tool: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe

Fetching code coverage report information from TFS…

Attempting to locate a test results (.trx) file…

Looking for TRX files in: D:\a\1\TestResults

No test results files found

Hello @sandeep_ravindran , could i ask you to properly format the YML using the “Preformatted Text” tool? A simple syntax mistake could lead to the problem, so it is important that the YML have proper indentation and formatting.

Did you followed our documentation? Including:

Notes on importing .NET reports

.NET reports are imported into SonarCloud in 4 steps:

1. Run the SonarScanner.MSBuild.exe `begin` command, specifying the absolute path where the reports *will be* available using the `/d:propertyKey="path"` syntax ("propertyKey" depends on the tool).
2. Build your project using MSBuild.
3. Run your test tool, instructing it to produce a report at the same location specified earlier to the SonarScanner for .NET.
4. Run the SonarScanner.MSBuild.exe `end` command.