SonarScanner giving 'MsBuild.exe' is not r

2019-07-27 13:54发布

问题:

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?

回答1:

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