msbuild - 使用 Team City 环境变量覆盖项目属性

标签 msbuild teamcity

我有一个名为 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/

相关文章:

MSBuild任务以执行外部MSBuild文件

msbuild - 出现编译错误时立即停止MSBuild处理

msbuild - MsTest 是 Microsoft Build Tools 的一部分吗?

c# - Azure DevOps Build 缺少程序集引用

.net - 从 MSBuild 项目中获取输出文件

svn - TeamCity - SVN 和标签 : How to do it correctly?

encoding - Teamcity 构建日志

Java静态分析器自定义模板/规范

TeamCity 提取工件依赖项

teamcity - 在 Teamcity 上选择较旧的依赖构建