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="&quot;$(MSBuildTools15_0_x86_Path)\msbuild.exe&quot; @(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.
1
2 comments

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.

0
Avatar
Permanently deleted user

I have found that I can use the MSBuild reserved property $MSBuildBinPath for this:

 

<Exec Command="$(SonarScannerMSBuildPath) begin /d:sonar.verbose=$(SonarScannerVerboseLogging) /k:&quot;<$(SonarProjectKey)&quot; /n:&quot;$(SonarProjectName)&quot; /v:&quot;$(Build_Number)&quot;" WorkingDirectory="$(MSBuildThisFileDirectory)" />

<Exec Command="&quot;$(MSBuildBinPath)\msbuild.exe&quot; @(Solution) /t:Rebuild" />

<Exec Command="$(SonarScannerMSBuildPath) end" WorkingDirectory="$(MSBuildThisFileDirectory)" />

 

1

Please sign in to leave a comment.