I have a working MSBuild file with certain targets that I want to run in a TFS build. The targets rely on certain environment variables and MSBuild properties being already defined. I have a "Variables" tab in my TFS build definition editor where I can ostensibly set the values of variables so that they are indeed defined when the targets run, but it seems that only literal values are allowed - if I want to define a variable in terms of another variable (eg %OTHER_VARIABLE%\subfolder
), there is no variable expansion happening. I've tried various ways of specifying the other variable (eg $(OTHER_VARIABLE)
) but the value is always seen literally by MSBuild.
Is there a way to define a variable in terms of another variable?
If you are using TFS 2015, You can use this extension:
https://marketplace.visualstudio.com/items?itemName=jessehouwing.jessehouwing-vsts-variable-tasks
https://github.com/jessehouwing/vsts-variable-tasks/wiki/Expand-Variable
When you define a variable in the Variables screen and use other variables as value, they won't be expanded (as you may have expected). Instead the literal text is passed to the tasks in the workflow. Without this little task the following configuration won't work:
Variable Value
Build.DropLocation \\share\drops\$(Build.DefinitionName)\$(Build.BuildNumber)
By adding the Expand variable(s) task to the top of your workflow, it will take care of the expansion, so any task below it will receive the value you're after.