SonarScanner giving 'MsBuild.exe' is not recognized as an internal or external command on TFS 2018
Asked Answered
Z

2

7

I'm adding SonarQube to existing TFS 2018 builds. I was following the directions for downloading Community Edition 7.4 located here https://docs.sonarqube.org/display/SCAN/Install+the+SonarScanner+for+MSBuild.

Going through the steps of the Quick Installation Guide https://docs.sonarqube.org/latest/setup/get-started-2-minutes/ I get to the part where I’m asked to “Execute the Scanner for MSBuild from your computer” using the below commands:

  1. SonarScanner.MSBuild.exe begin /k:"{key}" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="{key}"
  2. MsBuild.exe /t:Rebuild
  3. SonarScanner.MSBuild.exe end /d:sonar.login="{key}"

When I run the first command it succeeds C:\sonar-scanner-msbuild-4.4.2.1543-net46> SonarScanner.MSBuild.exe begin /k:"{key}" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="{key}"

SonarScanner for MSBuild 4.4.2 Using the .NET Framework version of the Scanner for MSBuild Default properties file was found at C:\sonar-scanner-msbuild-4.4.2.1543-net46\SonarQube.Analysis.xml Loading analysis properties from C:\sonar-scanner-msbuild-4.4.2.1543-net46\SonarQube.Analysis.xml Pre-processing started. Preparing working directories... 13:32:09.468 Updating build integration targets... 13:32:09.5 Fetching analysis configuration settings... 13:32:10.173 Provisioning analyzer assemblies for cs... 13:32:10.173 Installing required Roslyn analyzers... 13:32:10.579 Provisioning analyzer assemblies for vbnet... 13:32:10.579 Installing required Roslyn analyzers... 13:32:10.735 Pre-processing succeeded.

However when I run the second command "MsBuild.exe /t:Rebuild" It fails with the following error:

C:\Program Files (x86)>MsBuild.exe /t:Rebuild 'MsBuild.exe' is not recognized as an internal or external command, operable program or batch file.

I confirmed I added/updated environmental variables %PATH%, MsBuild exists, I’m wondering if there’s an additional step not noted in the instructions for .NET 4.5 framework? Has anyone come across this error for .NET using TFS builds or has any thoughts?

Zoroaster answered 27/11, 2018 at 22:28 Comment(2)
You're following the wrong instructions. Look at this: docs.sonarqube.org/display/SCAN/…Flogging
Thanks for pointing me in the right direction Daniel. That corrected my issue... All systems are a go! -EdZoroaster
N
4

Try to enter exact path of msbuild e.g. for VS2017 Professional command should be:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\"MsBuild.exe /t:Rebuild
Norma answered 2/6, 2019 at 15:9 Comment(2)
Not sure why this was downvoted but it worked for me.Lab
yeah, this worked "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MSBuild.exe" I also had to use "dotnet-sonarscanner" instead of "SonarScanner.MSBuild.exe"Duplicature
C
0

Another solution may be to add msbuild.exe directory to PATH. A bit more of hussle but then you can easily use just command without providing the full path as shown in the other answer.

Instruction how to add to PATH: https://gist.github.com/nex3/c395b2f8fd4b02068be37c961301caa7

By msbuild.exe directory I mean folder where it sits e.g. "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin"

Constanta answered 9/7 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.