Variable to access MsBuild path
I use MsBuild scripts to compile .net code and am trying to send the code to SonarQube Scanner (previously we've used the SonarRunner).
When I call the commands:
- Sonar Begin
- MsBuild
- Sonar End
The process fails with errors implying that the directories aren't consistent.
I have managed to get around this by specifying the MsBuild version (such as):
<Exec Command=""$(MSBuildTools15_0_x86_Path)\msbuild.exe" @(Solution) /t:Rebuild" />
However, this forces the use of a specific version of MsBuild.
I would like to use the version of MsBuild as stipulated in the TeamCity step that appears in the msbuildPath parameter in the log:
[Step 1/1] Starting: D:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:D:\TeamCity\buildAgent\work\488e6f245ac98af3 "/msbuildPath:C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin\MSBuild.exe"
Is there a variable for this? As if the version of MsBuild is changed in TeamCity I'd like it to pick it up without having to change the script.
We're using TeamCity 2017.1.4 but can upgrade if the variable is only in a newer version.
Thanks.
Please sign in to leave a comment.
Hi Graham,
I'm afraid it's not possible. You could run a script before your build step that selects the correct value in base of the configuration and sets up a parameter with it.
I have found that I can use the MSBuild reserved property $MSBuildBinPath for this:
<Exec Command="$(SonarScannerMSBuildPath) begin /d:sonar.verbose=$(SonarScannerVerboseLogging) /k:"<$(SonarProjectKey)" /n:"$(SonarProjectName)" /v:"$(Build_Number)"" WorkingDirectory="$(MSBuildThisFileDirectory)" />
<Exec Command=""$(MSBuildBinPath)\msbuild.exe" @(Solution) /t:Rebuild" />
<Exec Command="$(SonarScannerMSBuildPath) end" WorkingDirectory="$(MSBuildThisFileDirectory)" />