在 TFS 构建定义中,一个变量可以根据另一个变量定义吗?
In a TFS build definition, can a variable be defined in terms of another variable?
我有一个工作的 MSBuild 文件,其中包含我想在 TFS 构建中 运行 的某些目标。目标依赖于某些环境变量和已定义的 MSBuild 属性。我的 TFS 构建定义编辑器中有一个 "Variables" 选项卡,我可以在其中表面上设置变量的值,以便在目标 运行 时确实定义它们,但似乎只允许文字值 - 如果我想根据另一个变量(例如 %OTHER_VARIABLE%\subfolder
)定义一个变量,不会发生变量扩展。我已经尝试了各种指定其他变量的方法(例如 $(OTHER_VARIABLE)
),但 MSBuild 始终按字面意义查看该值。
有没有办法根据另一个变量来定义一个变量?
如果您使用的是 TFS 2015,您可以使用此扩展程序:
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.
我有一个工作的 MSBuild 文件,其中包含我想在 TFS 构建中 运行 的某些目标。目标依赖于某些环境变量和已定义的 MSBuild 属性。我的 TFS 构建定义编辑器中有一个 "Variables" 选项卡,我可以在其中表面上设置变量的值,以便在目标 运行 时确实定义它们,但似乎只允许文字值 - 如果我想根据另一个变量(例如 %OTHER_VARIABLE%\subfolder
)定义一个变量,不会发生变量扩展。我已经尝试了各种指定其他变量的方法(例如 $(OTHER_VARIABLE)
),但 MSBuild 始终按字面意义查看该值。
有没有办法根据另一个变量来定义一个变量?
如果您使用的是 TFS 2015,您可以使用此扩展程序:
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.