Search code examples
msbuildtfsbuildtfs-2015

Use $(SolutionName) in the MsBuild commandline parameters


In order to emulate the "PerProject" option in TFS 2013's XAML build in the new Build 2015 task based builds, I'd like to be able to pass the SolutionName to the msbuild commandline arguments without having to manually set it every time.

I'd like to do something like:

/p:OutputPath=$(Build.BinariesDirectory)\$(SolutionName)\

Where I'd like MsBuild to infer the $(SolutionName) parameter. But when passing this on the commandline, the new task runner will substitute the $(Build.BinariesDirectory) with the correct target path and leaves $(SolutionName) alone. Unfortunately MsBuild subsequently also leaves the property alone:

Copying file from "obj\Debug\TFSBuild.exe" to "bin\debug\$(SolutionName)\TFSBuild.exe".
TFSBuild -> b\$(SolutionName)\TFSBuild.exe
Copying file from "obj\Debug\TFSBuild.pdb" to "b\$(SolutionName)\TFSBuild.pdb".

I can't remember a way to pass a property to the commandline and have it do late-expansion... Any tips?

For those looking to emulate SingleFolder or AsConfigured, those are easy:

SingleFolder -> /p:OutputPath="$(Build.BinariesDirectory)"
Asconfigured -> don't pass OutputPath
PerProject   -> /p:OutputPath="$(Build.BinariesDirectory)\HARDCODESOLUTIONNAME"

Solution

  • As I feared there doesn't seem to be a simple way to override a property from the commandline and "inject" the value of another property into it during the evaluation stage.

    There are a few ways to get around it, but they're not ideal and certainly not universal for each language supported by MsBuild. A pity.

    I've debugged the MsBuild targets files and found a solution to reproduce the old behaviour from the 2005/2008 era. Not entirely per solution, but it does redirect projects into a subfolder.

     /p:GenerateProjectSpecificOutputFolder=true /p:OutDirWasSpecified=true
     /p:OutputPath=$(Build.BinariesDirectory)