title: TFS 2017 test task run fails on VS 2017 build machine if code coverage is enabled
body: <p>We're executing a number of tests on a build machine with VS 2017 Enterprise where we've enabled code coverage on the Visual Studio test task. This fails with the following error in the TFS 2017 console:</p>
  
  <pre><code>##[section]Starting: Test Assemblies **\*test*.dll
  Preparing task execution handler.
  Executing the powershell script: d:\builds\4\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\1.0.60\VSTest.ps1
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform
  Working folder: d:\builds\4\3\s
  Executing C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe "d:\builds\4\3\s\Source\u.a.testassembly.dll"  /Settings:"C:\Users\username\AppData\Local\Temp\tmp9CCF.tmp" /EnableCodeCoverage /logger:trx /TestAdapterPath:"d:\builds\4\3\s"
  Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
  Copyright (c) Microsoft Corporation.  All rights reserved.
  
  ##[error]The test source file "/EnableCodeCoverage" provided was not found.
  </code></pre>
  
  <p>With Visual Studio 2015 enterprise the tests were executed with code coverage with no error.</p>
  
  <p>We're supplying the path for the vstest.console.exe file as a custom path.</p>
  
  <p>If I disable code coverage in the checkbox for the TFS 2017 'Visual Studio Test' task and use a runsettings file with no code coverage collectors specified, the tests are executed, but no code coverage is reported.</p>
  
  <p>I've also tried with the code coverage checkbox disabled and the </p>
  
  <pre><code>/EnableCodeCoverage
  </code></pre>
  
  <p>argument supplied as a commandline parameter on the test tasks. That provides the same error as above.</p>
  
  <p>I've found a number of people having issues with code coverage in VS 2017 but that mostly seems related to .NET core project?</p>
  
  <p>Thank you for your help! :-)</p>
  
  <h3>UPDATE 1</h3>
  
  <p>If I try to run vstest.console.exe through the developer command prompt I'm unable to successfully specify the <code>/EnableCodeCoverage</code> option. It provides the following error message:</p>
  
  <pre><code>Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
  Copyright (c) Microsoft Corporation.  All rights reserved.
  
  The test source file "/EnableCodeCoverage" provided was not found.
  </code></pre>
  
  <p>This errormessage does not appear if I run the exact same command without the above switch.</p>
  
  <h3>Update 2</h3>
  
  <p>If I use a Runsettings file instead, in which I specify the datacollectors, I get a JSON related error:</p>
  
  <pre><code>Cannot deserialize the current JSON object (e.g. {"name":"value"}) 
  into type 'System.Collections.ObjectModel.Collection`1 Microsoft.VisualStudio.TestPlatform.ObjectModel.AttachmentSet]' 
  because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
  </code></pre>
  
  <p>If I use the /Diag switch I get the following stacktrace in a logfile:</p>
  
  <pre><code>Stack Trace:
  ved Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
  ved Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
  ved Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
  ved Newtonsoft.Json.Linq.JToken.ToObject(Type objectType, JsonSerializer jsonSerializer)
  ved Newtonsoft.Json.Linq.JToken.ToObject[T](JsonSerializer jsonSerializer)
  ved Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.JsonDataSerializer.DeserializePayload[T](Message message)
  ved Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.&lt;&gt;c__DisplayClass6_0.&lt;AfterTestRunEnd&gt;b__0()
  ved Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.ProxyDataCollectionManager.InvokeDataCollectionServiceAction(Action action, ITestMessageEventHandler runEventsHandler)
  </code></pre>
  
  <h3>Update 3</h3>
  
  <p>Our build server is a Windows 2012 standard server. We were able to install VS 2017 without any errors except for the installation of the Windows SDK payload. We had to manually install  Windows SDK for Windows 8 afterwards as Windows SDK payload included in the VS 2017 Enterprise didn't install on Windows server 2012.</p>
  
  <p>I've just noticed that Windows Server 2012 isn't on <a href="https://www.visualstudio.com/en-us/productinfo/vs2017-system-requirements-vs#visual-studio-2017" rel="nofollow noreferrer">the list of supported operating systems</a> for VS 2017?...</p>
  
  <h3>Update 4</h3>
  
  <p>The detailed output from 
      vstest.console.exe /?
  when run from the VS 2017 developer command prompt is:</p>
  
  <pre><code>Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
  Copyright (c) Microsoft Corporation.  All rights reserved.
  
  Usage: vstest.console.exe [Arguments] [Options] [[--] &lt;args&gt;...]]
  Description: Runs tests from the specified files.
  </code></pre>
  
  <p>It then lists all of the arguments. The</p>
  
  <pre><code>/Enablecodecoverage
  </code></pre>
  
  <p>switch is nowhere to be found. The Developer Command Prompt is opened using the shortcut in the Start menu.</p>
  
  <p>I've tried to run a test suite where the datacollector was defined in a .runsettings file instead of using the /enablecodecoverage switch, but that produces the JSON error listed above.</p>
  
  <h3>Update 5</h3>
  
  <p>After upgrading our TFS on-premise to 2017 update 1 we we're able to successfully execute our unit tests AND get code coverage.</p>
  
  <p>We are however using SonarQube and apparently at this time of writing the SonarQube scanner provided in the Marketplace Extension v. 3.0.0 doesn't correctly locate the code coverage report due to the change in registry keys done in VS 2017.</p>
  
  <p>A <a href="https://jira.sonarsource.com/browse/SONARMSBRU-330?jql=project%20%3D%20SONARMSBRU" rel="nofollow noreferrer">bug report has been filed with SonarQube</a> on this issue.</p>
  
  <p>You can get around this limitation by manually creating a registry value named 'ShellFolder' under the follow registry key:</p>
  
  <pre><code>HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\15.0
  </code></pre>
  
  <p>The 'ShellFolder' string value should then be:</p>
  
  <pre><code>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise
  </code></pre>
  
  <p>I've left the above information here in case somebody else comes looking with same problems that we had.</p>