CodeCoverage not found when installed by Visual Studio Test Platform Installer


(Bouke) #1

I’m using the “Visual Studio Test Platform Installer” in Azure DevOps, which installs the Microsoft.TestPlatform nuget package. This tool provides CodeCoverage.exe. However SonarQube doesn’t discover this tool:

2019-02-18T14:09:21.1495521Z 15:09:21.149  Attempting to locate the CodeCoverage.exe tool...
2019-02-18T14:09:21.1535493Z 15:09:21.153  Attempting to locate the CodeCoverage.exe tool using setup configuration...
2019-02-18T14:09:21.1655459Z 15:09:21.165  Attempting to locate the CodeCoverage.exe tool using registry...
2019-02-18T14:09:21.1695696Z 15:09:21.168  15:09:21.168  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.

As a workaround, I now generate the coverage XML manually, adapted from a workaround posted to the mailing list.

  testPlatformVersion: 15.9.0
- task: VisualStudioTestPlatformInstaller@1
  displayName: 'Visual Studio Test Platform Installer'
    versionSelector: specificVersion
    testPlatformVersion: '$(testPlatformVersion)'
# steps to prepare, build, test, analyze etc
- powershell: |
   $cc = "$(Agent.ToolsDirectory)\VsTest\$(testPlatformVersion)\x64\tools\net451\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"
   $root = '$(Build.SourcesDirectory)\TestResults'
   $trxFile = (Get-ChildItem -Path $root -Filter *.coverage -Recurse | Select-Object -First 1).fullname
   $guid = New-Guid
   $out = "$root\$guid.coveragexml"
   &$cc analyze /output:$out $trxFile
   exit 0
  displayName: 'Convert coverage report to xml'