Can't find CodeCoverage in ADO pipeline

Hello !

I’m trying to get the analysis to find the codecoverage.exe. It exists in several locations but setting VsTestToolsInstallerInstalledToolLocation is no help

SonarQube 9.6.1
Azure Build Agent : 2.209.0
Node.js 18.12.1
SonarQube ADO Tasks : 5.8.1
NO Visual Studio installation

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...
WARNING: CodeCoverage.exe was not found in the standard locations. Please provide the full path of the tool using the VsTestToolsInstallerInstalledToolLocation variable.
Attempting to locate the CodeCoverage.exe tool using setup configuration...
Attempting to locate the CodeCoverage.exe tool using registry...
WARNING: Failed to find the code coverage command line tool. Possible cause: Visual Studio is not installed, or the installed version does not support code coverage

Summed up pipeline :

  • Get lastest .Net core 6.x sdk
  • Prepare Analysis Configuration task : MSBuild scanner Mode
  • dotnet test -c "Dev" --collect "XPlat Code Coverage" --results-directory $(Common.TestResultsDirectory) --logger trx
  • Run Code Analysis task

What I tried :

  1. Setting VsTestToolsInstallerInstalledToolLocation to D:\Agents\agent3\_work\_tool\VsTest\17.4.0\x64\tools\net462\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe
  2. Setting VsTestToolsInstallerInstalledToolLocation to D:\Agents\agent3\_work\_tool\VsTest\17.4.0\x64\tools\net462\Team Tools\Dynamic Code Coverage Tools\amd64\CodeCoverage.exe
  3. nuget install Microsoft.CodeCoverage in a directory and setting VsTestToolsInstallerInstalledToolLocation to that directory
  4. Adding the Microsoft.CodeCoverage NuGet package to the xUnit test project of my solution

We have another build server where Visual Studio is installed and CodeCoverage is found successfully.
We don’t want to install it on this server as it’s unecessary.

Any help appreciated !
Thank you

1 Like

Hello @Narfix

Your setting for VsTestToolsInstallerInstalledToolLocation looks right. You have to include CodeCoverage.exe in the path as you did.
Therefore our assumption is, that the tool is not in the path specified by the environment variable. Can you make sure that the tool is actually installed at the location(s) specified?

Best, Martin


I faced the same error. The environment variable is set by VisualStudioTestPlatformInstaller, but only the root path for all test-tools. The variable must be overwritten in the pipeline exactly for CodeCoverage.exe.
Like this

- task: PowerShell@2
  displayName: Set path for CodeCoverage.exe
    targetType: 'inline'
    script: |
      Write-Host "VsTestToolsInstallerInstalledToolLocation value before: $($env:VsTestToolsInstallerInstalledToolLocation)"
      Write-Host "Update VsTestToolsInstallerInstalledToolLocation environment variable."
      $path=($env:VsTestToolsInstallerInstalledToolLocation) + "\tools\net462\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"
      Write-Host "##vso[task.setvariable variable=VsTestToolsInstallerInstalledToolLocation;]$($path)"
      Write-Host "VsTestToolsInstallerInstalledToolLocation value after: $($env:VsTestToolsInstallerInstalledToolLocation)"

Whatever the reason, very confusing construct :upside_down_face:

Azure DevOps Server 2020 & SonarQube on-premise.

1 Like


I had the same problem. I tried your solution :

and… it’s OK now.

Thank you!

Hello @kle

Thank you for sharing your solution to the problem. I’d like to better understand the root cause, so we can provide a fix and the workaround posted by you is no longer needed. Could you please share your VsTestPlatformToolInstallerV1 configuration, so we can reproduce the issue and see what we can do to find the coverage tool if the environment variable is set by the VsTestPlatformToolInstallerV1 task?

The path to CodeCoverage.exe changed. We need to fix VsTestToolsInstallerInstalledToolLocation: Path to CodeCoverage.exe may contain net462 instead of net451 · Issue #1357 · SonarSource/sonar-scanner-msbuild · GitHub to fix the root cause.

Hello Martin,
glad you found the bug in the meantime. Anyway, here is my VisualStudioTestPlatformInstaller configuration - it’s pretty much standard:

- task: VisualStudioTestPlatformInstaller@1
    packageFeedSelector: 'nugetOrg'
    versionSelector: 'latestStable'
1 Like

Sorry… didn’t get the reply notifications
thank you @kle @pascalPPA @Martin_Strecker !! :smiling_face_with_three_hearts:

1 Like

While I confirm the this works with .net SDK 6.0, it doesn’t with .net SDK 7.0

1 Like

Hello @Narfix,

While I confirm that this works with .net SDK 6.0, it doesn’t with .net SDK 7.0

As far as I know, CodeCoverage.exe is not part of the .net SDK. Do you install the tool via the VisualStudioTestPlatformInstaller@1 task as described above? Can you please post the relevant parts of your pipeline (.Net SDK installation, Test platform installation)? I’m working on a fix right now and want to make sure it works in your configuration.

My bad… wrong order within the steps in my CI

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.