After seeing my code coverage was no longer being shown in SonarQube, I found the following error in my VSTest task log output when running on a private build agent.
2018-03-09T16:26:39.2215918Z Starting test execution, please wait…
2018-03-09T16:26:39.7123032Z 2.3365
2018-03-09T16:26:39.7236043Z Data collector ‘Code Coverage’ message: Cannot find CodeCoverage.exe..
2018-03-09T16:26:42.2546571Z NUnit Adapter 3.9.0.0: Test execution started
I installed Agents for Visual Studio 2017 (which includes CodeCoverage.exe) and Build Tools for Visual Studio 2017 in addition to Visual Studio 2017 Community which was already installed. But no change.
After further troubleshooting and research I reported the problem to Microsoft by creating an issue on Developer Community. A Microsoft support person responded suggesting to uninstall VS2017 Community because when installed it gets confused on the path.
With Community removed, my next build errors were:
Error MSB4226: The imported project “C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets” was not found.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v15.0\SSDT
Error MSB4062: The “SqlModelResolutionTask” task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\Extensions\Microsoft\SQLDB\Dac\140\Microsoft.Data.Tools.Schema.Tasks.Sql.dll.
Apparently the Build Tools do not *yet* (see below) contain all the same build tools that VIsual Studio has. The suggestion was to install Visual Studio Enterprise to solve both problems (coverage and SSDT). I really don’t like installing Visual Studio on my build agent so instead I just copied the folders from the Community edition on my local machine to the corresponding paths under Build Tools on my build server and that fixed it for me.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\VisualStudio\v15.0\SSDT
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\Microsoft\SQLDB
I’m sure installing VS Enterprise would have solved the problem if you like that solution better.
The support person did mention Microsoft is having some of these same issue internally as well and they are trying to improve the build tools. So maybe this will be fixed one day. Until then I hope this post helps others work around these issue.
Happy building!