我有一个名为 Version 的 C# 项目属性定义为
<Version Condition="$(Version)==''">1.2.3.4<Version>
1.2.3.4 是默认值。
我有一个团队城市系统属性,也称为版本,设置为覆盖。因此,在 Team City 的自定义运行对话框中,我可以为 Version 指定一个值并使用该值。这工作正常。
但是,如果我将 Team City 中的参数留空,默认值仍会被空白(空?)覆盖。如果我删除 Team City 参数,则使用默认值。
条件不正确?如何将 Team City 属性设置为空白,并且仅在输入某个值时覆盖?
最佳答案
OP评论后更新答案:
从文档:
MSBuild allows you to set properties from the command line using the /property or /p command line switch. Property values received from the command line override property values set in the project file and property values inherited from environment variables.
所以你可以在 TeamCity 配置中设置一个属性 $(VersionTC) 并检查该属性是否为空并设置版本
<Version>$(VersionTC)<Version>
<Version Condition="'$(VersionTC)'==''">1.2.3.4<Version>
(因此您首先将
Version
设置为 VersionTC
。然后查看它是否为空并设置默认值)看看这个 blog post解释这一切。
尝试如下:
<Version Condition=" '$(Version)'=='' ">1.2.3.4<Version>
请注意
' '
(单引号)左右$(Version)
关于msbuild - 使用 Team City 环境变量覆盖项目属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6129720/