We had to manually add a registry key to get this to work
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