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
    inputs:
    SonarCloud: (Sonar.cloud) organization: (Sonar.organization)
    scannerMode: (Sonar.scannerMode) projectKey: (Sonar.cliProjectKey)
    projectName: (Sonar.cliProjectName) extraProperties: | sonar.cs.opencover.reportsPaths=(Build.SourcesDirectory)/**/coverage.opencover.xml
    sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
    • task: VSBuild@1
      inputs:
      solution: ‘**/*.sln’
      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: '(MSBuild.buildPlatform)’
      configuration: ‘$(MSBuild.buildConfiguration)’

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

    • task: VSTest@2
      displayName: Sonartest
      inputs:
      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
      inputs:
      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