我有一个工作 MSBuild 文件,其中包含我想要在 TFS 构建中运行的某些目标。这些目标依赖于已定义的某些环境变量和 MSBuild 属性。我的 TFS 构建定义编辑器中有一个“变量”选项卡,表面上我可以在其中设置变量的值,以便在目标运行时确实定义它们,但似乎只允许使用文字值 - 如果我想定义变量就另一个变量(例如%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.
关于tfs - 在 TFS 构建定义中,可以根据另一个变量定义一个变量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34007455/