2

The following MSBuild script works, but I have to hard code the work folder (GetAssemblyIdentity line) that TeamCity uses.

How do I get "C:\TeamCity\buildAgent\work\cb8ffbe14de0bdf3" dynamically?

<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>
Ian Vink
  • 66,960
  • 104
  • 341
  • 555
  • 1
    Could you use a path relative to the MSBuild project file, using $(MSBuildProjectDirectory) property? – Giulio Vian Oct 24 '14 at 19:49
  • 1
    teamcitty.build.working.dir can be injected into the MSBuild build parameters on the command line (something like "/p:AgentWorkFolder=teamcity.build.working.dir" can be used on the MSBuild command line). See https://confluence.jetbrains.com/display/TCD8/Predefined+Build+Parameters#PredefinedBuildParameters-AgentBuildProperties Then use ... GetAssemblyIdentity AssemblyFiles="$(AgentWorkFolder)\..." in your target. – d3r3kk Oct 24 '14 at 19:57

1 Answers1

1

You could use the built-in teamcity variables. Change your code to:

<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>
James Woolfenden
  • 6,498
  • 33
  • 53