Issue with C# Code Coverage with VSTS and Visual Studio 2017

2,511 views
Skip to first unread message

ianbf...@gmail.com

unread,
May 25, 2017, 10:35:07 AM5/25/17
to SonarQube
I am using the extension for VSTS to run analysis through a build server running Visual Studio 2017. Currently the Complete task is never trying to find my .trx file so that code coverage for C# can be uploaded. I have checked my build server and it has the .trx and the .coverage file is specified in the file and I can find it on the build server.

During the Complete task I am getting a warning (" 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."), but the build server has code coverage because my VSTS build has the code coverage.

I am guessing these issue are connected, but I cannot understand why this issue is happening. Any help would be appreciated and hopefully it is a simple issue

ianbf...@gmail.com

unread,
May 26, 2017, 8:08:27 AM5/26/17
to SonarQube, ianbf...@gmail.com
Has any one else had this issue?

ianbf...@gmail.com

unread,
Jun 1, 2017, 9:02:42 AM6/1/17
to SonarQube, ianbf...@gmail.com
Does anyone know if the VSTS plugin will only look for the CodeCoverage.exe on the C Drive? I have Visual Studio installed on the Build server on another Drive.

==============================================================================
Task         : SonarQube  Scanner for MSBuild - End Analysis (new)
Description  : Complete the SonarQube analysis of your solution
Version      : 2.1.2
Author       : SonarSource
Help         : Version: 2.1.2. [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================


On Thursday, May 25, 2017 at 9:35:07 AM UTC-5, ianbf...@gmail.com wrote:

Julien HENRY

unread,
Jun 1, 2017, 9:57:21 AM6/1/17
to SonarQube, ianbf...@gmail.com
Hi,

Here is the way CodeCoverage.exe is located:
  1) we get Visual Studio installations directories by reading the registry entries at SOFTWARE\Microsoft\VisualStudio
  2) path to the CodeCoverage tool is computed by appending Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe

Does it matches your installation?

++

Julien

ianbf...@gmail.com

unread,
Jun 1, 2017, 11:57:23 AM6/1/17
to SonarQube, ianbf...@gmail.com
Thank you for the reply Julien.

Can you be more specific on which Registry Entry you use. Which HKey and the exact tree from VisualStudio you use. I am looking at the registry entries on my build server and cannot find a install directory

ianbf...@gmail.com

unread,
Jun 2, 2017, 1:41:32 PM6/2/17
to SonarQube, ianbf...@gmail.com
From what I have been reading it also looks like 2017 does not use the registry like older versions of Visual Studio.

Any idea how I can get the Code coverage to start working with the VSTS plugin, since vs2017 does not have registry entries.


ianbf...@gmail.com

unread,
Jun 2, 2017, 1:44:26 PM6/2/17
to SonarQube, ianbf...@gmail.com

ianbf...@gmail.com

unread,
Jun 6, 2017, 11:20:47 AM6/6/17
to SonarQube, ianbf...@gmail.com
Julian,

Did you get a change to look through my posts and do you know if SonarQube plugin is handling this? or is there a way to make the plugin check the code coverage even when it does not find Visual Studio's Code Coverage Tool?


On Thursday, June 1, 2017 at 8:57:21 AM UTC-5, Julien HENRY wrote:

ianbf...@gmail.com

unread,
Jun 13, 2017, 4:06:09 PM6/13/17
to SonarQube, ianbf...@gmail.com
I am still hoping to get a answer to my question in this post. Does anyone know a answer?

PJ Khatri

unread,
Jun 13, 2017, 10:04:25 PM6/13/17
to SonarQube
I just posted on this in this group as a defect.

We had to manually add a registry key to get this to work

ianbf...@gmail.com

unread,
Jun 14, 2017, 11:26:16 AM6/14/17
to SonarQube
What was the registry key that you added? and where?

PJ Khatri

unread,
Jun 14, 2017, 1:06:43 PM6/14/17
to SonarQube, ianbf...@gmail.com
If you follow the code being run here under GetExeToolPath and GetVsShellFolders, you will see that you can add a setting under SOFTWARE\Microsoft\VisualStudio and once you add a ShellFolder value under that, which contains the VS 2017 path, then it will work.

a.kor...@mephix.com

unread,
Jul 4, 2017, 8:49:56 AM7/4/17
to SonarQube, ianbf...@gmail.com

So the referenced Sonar scanner code checks the registry at HKLM\SOFTWARE\Microsoft\VisualStudio and looks for installed versions of Visual Studio. For each version it then checks for a key named ShellFolder to get the Visual Studio installation folder. Of all the installed versions found, it will use the version of Visual Studio with the highest version number. The relative path to the code coverage tool is then added to the ShellFolder path, resulting in a complete path to (the most recent version of) CodeCoverage.exe.


In our situation, the CodeCoverage.exe tool is located at: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"

Which means that if we add the following registry key (version 15.0 is VS2017):


Path:  HKLM\SOFTWARE\Microsoft\VisualStudio\15.0
Key:   ShellFolder
Value: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise


Sonarqube scanner should be able to find the CodeCoverage.exe tool. However, in our logs still shows: "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."

We are using TFS2017.1 with SonarQube scanner 2.1.2 and with VS2017 Enterprise installed on our build servers.

mail.me...@gmail.com

unread,
Aug 6, 2017, 10:21:21 PM8/6/17
to SonarQube, ianbf...@gmail.com, a.kor...@mephix.com
Will this issue resolve in future version without requiring the update to the registry? I cannot update the registry on Hosted agent on Visual Studio Online as I do not have permissions. 

mail.me...@gmail.com

unread,
Aug 6, 2017, 10:49:34 PM8/6/17
to SonarQube, ianbf...@gmail.com, a.kor...@mephix.com, mail.me...@gmail.com
Looks like the issue is fixed recently and is available in version 3.0.1 of SonarQube tasks of VSO. https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube 

I will update the thread once we get this update approved by my admin.

Ian Farrell

unread,
Aug 7, 2017, 9:30:50 AM8/7/17
to mail.me...@gmail.com, SonarQube, a.kor...@mephix.com
I updated my scanner, but now I am having problems getting builds to complete. I keep getting a error about a SonarQube file trying to be delete and it not being allowed. I did not have this problem on v2.* of the scanner, only v3.*


Ian B. Farrell

nicolas...@sonarsource.com

unread,
Aug 7, 2017, 9:51:29 AM8/7/17
to SonarQube, mail.me...@gmail.com, a.kor...@mephix.com, ianbf...@gmail.com
Hi Ian,

If you're having a different problem now then better take it independently from this thread here. First look for other threads related to that latest error, and if needed then open a new one, will all relevant details and logs.

Best regards,
Nicolas

a.kor...@mephix.com

unread,
Aug 18, 2017, 1:39:12 AM8/18/17
to SonarQube, ianbf...@gmail.com, a.kor...@mephix.com
Can someone please post the exact values of their registry keys as a workaround to this problem?

a.kor...@mephix.com

unread,
Sep 11, 2017, 8:16:24 AM9/11/17
to SonarQube
As more and more of our projects use VS2017 build servers, this issue becomes more urgent. I would still like to see a solution or at least a workaround to get code coverage available again.

I have already tried to add the correct path to the registry, but SonarQube is still unable to find the code coverage commandline tool.

Thanks in advance.

Regards,
Arjen

a.kor...@mephix.com

unread,
Oct 6, 2017, 8:36:30 AM10/6/17
to SonarQube
More than 4 months and still no solution ?

Come on SonarQube!


On Thursday, May 25, 2017 at 4:35:07 PM UTC+2, ianbf...@gmail.com wrote:

Josh Handel

unread,
Nov 29, 2017, 4:53:46 PM11/29/17
to SonarQube
Current issue seems to be that vs-test creates the binary .coverage file not a .coveragexml.. I am exploring a powershell script to add to the build tasks to process the coverage into a coveragexml that sonarqube can handle.. I'll post something if it works.

Josh

Josh Handel

unread,
Nov 30, 2017, 2:46:59 PM11/30/17
to SonarQube
So I got the coveragexml file to generate with the below powershell.. But despite adding the commandline argument "/d:sonar.cs.vscoveragexml.reportsPaths" to the begin analizing step its still not finding the file.

Here is the powershell to generate the coveragexml from the coverage file
$cc = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Dynamic Code Coverage Tools\CodeCoverage"
$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

But its kind of useless until someone can share how to get sonarqube to actually find the file during the Complete SonarQube analysis

kind of bummed.. been working on this for 3 days... and it shouldn't be this hard.

Josh Handel

unread,
Nov 30, 2017, 3:03:11 PM11/30/17
to SonarQube
to be clear /d:sonar.cs.vscoveragexml.reportsPaths=”**\*.coveragexml"  is the added command argument... 

Josh Handel

unread,
Nov 30, 2017, 3:21:43 PM11/30/17
to SonarQube
SUCCESS!  removed the quotes from around the path and it finally found it.

Josh

G. Ann Campbell

unread,
Nov 30, 2017, 4:02:04 PM11/30/17
to SonarQube
Congrats Josh!

Thanks for following up.


:-)
Ann

ianbf...@gmail.com

unread,
Dec 1, 2017, 10:08:36 AM12/1/17
to SonarQube
I am glad we have a work around. But when is SonarQube going to fix this problem.


On Thursday, May 25, 2017 at 9:35:07 AM UTC-5, ianbf...@gmail.com wrote:

duncan.po...@sonarsource.com

unread,
Dec 4, 2017, 12:46:03 PM12/4/17
to SonarQube
FYI the issue is being tracked in SONARMSBRU-361. We've included this issue in the current bug-fixing sprint.

Regards,
Duncan

a.kor...@mephix.com

unread,
Mar 12, 2018, 5:41:14 AM3/12/18
to SonarQube
This is a different issue. Your workaround to change the coverage xml file therefor wont solve the issue that the code coverage tool cannot be found.
Reply all
Reply to author
Forward
0 new messages