我的TeamCity构建中有一个变量,当我尝试将此变量解析为失败的字符串时,该变量看起来像3.12.2323.0。这是我的代码:
$versionNumber = %build.version.major%.%build.version.minor%.%build.counter%."0"
我也试过
$versionNumber = %build.version.major%+%build.version.minor%+%build.counter%+"0"
我的错误是:
Unexpected token '.1682' in expression or statement.
[19:40:18][Step 2/2] At line:1 char:27
[19:40:18][Step 2/2] + $versionNumber = 3.13.1682 <<<< ."0"
[19:40:18][Step 2/2] + CategoryInfo : ParserError: (.1682:String) [], ParentContainsErrorRecordException
[19:40:18][Step 2/2] + FullyQualifiedErrorId : UnexpectedToken
[19:40:18][Step 2/2]
答案 0 :(得分:1)
我没有TeamCity的经验,但假设%build.version.major%
等。是环境变量,您可以像这样构建您的版本字符串:
$versionNumber = '{0}.{1}.{2}.0' -f ${env:build.version.major},
${env:build.version.minor}, ${env:build.counter}
答案 1 :(得分:0)
感谢PetSerAl和jisaak我混合使用了你的两个建议并且它有效。
答案:
$versionNumber = '{0}.{1}.{2}.0' -f %build.version.major%,%build.version.minor%,%build.counter%