Why not generate code coverage and PublishCodeCoverageResults@1 not works

C# .NET 4.7.2
With AzureDevOps and SonarCloud

- task: VSTest@2
  displayName: 'VSTest'
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\BProject.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    codeCoverageEnabled: true
    codeCoverageTool: 'Cobertura'
    failTaskOnFailedTests: true
    otherConsoleOptions: '/collect:"Code Coverage;Format=Cobertura"'
    summaryFileLocation: '$(Build.SourcesDirectory)/TestResults/'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish Code Coverage'
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: '$(Build.SourcesDirectory)/TestResults/'

PublishCodeCoverageResults@1 returns
##[warning]No code coverage results were found to publish.

Have a look on the output of your VSTest task. There you should see the full path of test result and code coverage files. The required files are often located in the Agent.TempDirectory.

1 Like