SonarScanner giving 'MsBuild.exe' is not recognized as an internal or external command on TFS 2018 - tfs

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:
SonarScanner.MSBuild.exe begin /k:"{key}" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="{key}"
MsBuild.exe /t:Rebuild
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?

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

Related

No coveragexml files in Scanner for MSBuild through VSTS extension

Using:
TFS 2017 Update-2
VS2015
VSTS Task 3.2.0
SonarQube 5.6.6 LTS
After the upgrade of the SonarQube Extension from 4.0.2 to 4.1 We get a warning when running the "Scanner for MSBuild - End Analysis" task.
We noticed that the codecoverage.xml files are not generated by the Code Coverage Tool (see logging below).
This only appears for TFS agents with VS2015 installed, it works fine for the same setup with VS2017.
We applied the work-around: SonarQube Code Coverage from VSTS
we put /d:sonar.cs.vscoveragexml.reportsPaths=**/*.coveragexml in the additional setting of the task "Scanner for MSBuild - Begin Analysis"
But stil no codecoverage.xmlfiles are produced
Is there another workaround or solution ?
2018-03-21T10:01:20.7772938Z ##[section]Starting: Complete the SonarQube analysis
2018-03-21T10:01:20.7929236Z ==============================================================================
2018-03-21T10:01:20.7929236Z Task : Scanner for MSBuild - End Analysis
2018-03-21T10:01:20.7929236Z Description : [DEPRECATED] Use new version of the task
2018-03-21T10:01:20.7929236Z Version : 3.2.0
2018-03-21T10:01:20.7929236Z Author : SonarSource
2018-03-21T10:01:20.7929236Z Help : [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
2018-03-21T10:01:20.7929236Z ==============================================================================
2018-03-21T10:01:20.7929236Z Preparing task execution handler.
2018-03-21T10:01:21.1835551Z Executing the powershell script: C:\TFS\Agent\_work\_tasks\SonarQubeScannerMsBuildEnd_6d01813a-9589-4b15-8491-8164aeb38055\3.2.0\SonarQubePostTest.ps1
2018-03-21T10:01:22.3867151Z WARNING: ------------------------------------------------------------------------
2018-03-21T10:01:22.3867151Z This executable is deprecated and may be removed in next major version of the SonarScanner for MSBuild. Please use 'SonarScanner.MSBuild.exe' instead.
2018-03-21T10:01:22.3867151Z ------------------------------------------------------------------------
2018-03-21T10:01:22.3867151Z SonarScanner for MSBuild 4.1
2018-03-21T10:01:22.3867151Z Using the .NET Framework version of the Scanner for MSBuild
2018-03-21T10:01:22.3867151Z Default properties file was found at C:\TFS\Agent\_work\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.2.0\SonarQubeScannerMsBuild\SonarQube.Analysis.xml
2018-03-21T10:01:22.3867151Z Loading analysis properties from C:\TFS\Agent\_work\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.2.0\SonarQubeScannerMsBuild\SonarQube.Analysis.xml
2018-03-21T10:01:22.3867151Z Post-processing started.
2018-03-21T10:01:22.3867151Z 11:01:21.761 11:01:21.746 WARNING: Failed to find the code coverage command line tool. Possible cause: Visual Studio is not installed, or the installed version does not support code coverage.
This issue is being tracked in #461 Failure to find VS2015 CodeCoverage.exe after searching for nonexistent registry key which lists the known workarounds (namely, manually add a registry key, or use VS2017 to build).
It should also work if the build agents have both VS2015 and VS2017 installed - the build can be performed using VS2015, but scanner end step should detect and use the VS2017 version of the code coverage tool.

No ProjectInfo.xml files were found .TFS build with sonar end task

I am trying to configure my visual studio project to send some analysis data to SonarQube server using TFS 2015 build (vnext)
I get this error in the Sonar end task.
##[error]No ProjectInfo.xml files were found. Possible causes:
##[error]1. The project has not been built - the end step was called right after the begin step, without a build step in between
An unsupported version of MSBuild has been used to build the project. Currently MSBuild 12.0 upwards are supported
We use MSBuild 14.0 in the server.
The SonarQube Scanner for MSBuild requires your project to be built
with MSBuild 14.0. We recommend installing Visual Studio 2015 on the
analysis machine in order to benefit from the integration and features
provided with the Visual Studio ecosystem (VSTest, MSTest unit tests,
etc.).
Suggest you to also install VS2015 on your build server, and since you are using MSbuild 14.0, double check if you are using the old task with deprecated in front which used for MSbuild 12.0. SonarQube Scanner for MSBuild released with static analysis which could executed during the build on MSbuild 14.0.
The support of MSBuild 12 by the SonarQube Scanner for MSBuild is
deprecated and will be removed in a future release.
Source: Compatibility with Visual Studio and MSBuild
Please download and use the latest version of the SonarQube Scanner for MSBuild in marketplace and try again. The recent documentation is available from Analyzing with SonarQube Extension for VSTS/TFS, you could also take a look at this tutorial.

No ProjectInfo.xml files were found Sonar scan

I am trying to configure my visual studio project to send some scan data to SonarQube server using TFS 2015 build (vnext)
I get this error in the Sonar end task.
##[error]No ProjectInfo.xml files were found. Possible causes:
##[error]1. The project has not been built
The end step was called right after the begin step, without a build step in between an unsupported version of MSBuild has been used to build the project. Currently MSBuild 12.0 upwards are supported.
We use MSBuild 14.0 in the server. it is a C++ project (VCXPROJ project File)

TFS 2010 issues building C#6.0 code with MS Build 14

We have TFS 2010 running happily on a dedicated build server.
I have installed Microsoft Build Tools 2015, which includes MS Build 14 successfully on the build machine, but not Visual Studio 2015.
I've created a custom template which alters the "ToolsPath" property of the "Run MSBuild" activity to "C:\Program Files (x86)\MSBuild\14.0\Bin".
The build runs, but fails on this particular error:
(CoreCompile target) ->
CSC : error CS1566: Error reading resource 'ProjectName.exe.licenses' --
'Could not find file 'C:\develop\Sources\ProjectName\obj\x86\Release\ProjectName.exe.licenses'.' [C:\develop\Sources\ProjectName\ProjectName.csproj]
The same project builds fine using Visual Studio 2015 running from another machine.
It makes no difference whether the TFS build definition includes these MS Build arguments or not:
/tv:14.0 /p:VisualStudioVersion=14.0
Does anybody have a success story of using a TFS 2010 build agent to successfully build a C#6.0 project?
I solved this in the end by installing Visual Studio 2015!
The /tv:14.0 /p:VisualStudioVersion=14.0 argument may don't work for MSBuild Tools.
You should customize the tfs build process template to set ToolPath of the Run MSBuild for Project to target to MSBuild14; and set ToolVersion to "14.0".
Check this link for the detailed information:BuildActivity ignores ToolsVersion

Building with a single x86 platform with TFS Build 2015 (build vNext)

I'm trying to build an universal Windows 10 app using TFS2015 and "build vnext" build system. Code is hosted on Visual Studio Online, build agent is deployed to a virtual machine running Windows 10 and VS2015 in Azure.
I created a simple MSBuild build definition and I specified "x86" as platform:
It looks like the agent is ignoring this parameter and building the .sln with all 3 platforms (x86, x64 and ARM).
In the log, the following command line is executed:
C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe "C:\build-agent\_work\1\s\src\App.sln" /nologo /m /nr:false /fl /flp:"logfile=C:\build-agent\_work\1\s\src\App.sln.log" /dl:CentralLogger,"C:\build-agent\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"C:\build-agent\agent\worker\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:Configuration=Debug /p:Platform=x86 /p:platform="x86" /p:configuration="debug" /p:VisualStudioVersion="14.0"
But then I can find the following traces:
Building solution configuration "Debug|x86"
Building solution configuration "Debug|x64"
Building solution configuration "Debug|ARM"
Any idea what could be causing this behavior ?

Resources