以下MSBuild脚本有效,但我必须对TeamCity使用的工作文件夹( GetAssemblyIdentity 行)进行硬编码。
我如何获得" C:\ TeamCity \ buildAgent \ work \ cb8ffbe14de0bdf3"的动态
<Target Name="GetVersion">
<GetAssemblyIdentity AssemblyFiles="C:\TeamCity\buildAgent\work\cb8ffbe14de0bdf3\AAA.Online.Web\bin\AAA.Online.Web.dll">
<Output TaskParameter="Assemblies" ItemName="myAssemblyInfo"/>
</GetAssemblyIdentity>
<PropertyGroup>
<Pattern>(\d+)\.(\d+)</Pattern>
<In>%(myAssemblyInfo.Version)</In>
<OutVersion>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</OutVersion>
</PropertyGroup>
</Target>
答案 0 :(得分:1)
您可以使用内置的teamcity变量。 将您的代码更改为:
<Target Name="GetVersion">
<GetAssemblyIdentity AssemblyFiles="$(teamcity_build_checkoutDir)\AAA.Online.Web\bin\AAA.Online.Web.dll">
<Output TaskParameter="Assemblies" ItemName="myAssemblyInfo"/>
</GetAssemblyIdentity>
<Message Text="Path is $(teamcity_build_checkoutDir)"/>
<PropertyGroup>
<Pattern>(\d+)\.(\d+)</Pattern>
<In>%(myAssemblyInfo.Version)</In>
<OutVersion>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</OutVersion>
</PropertyGroup>
</Target>