Can TeamCity read a custom MSBuild property?

Here is the use case: To version the artifacts using the AssemblyInfoPatcher, I want to set the major.minor.build components of the version from an MSBuild property and get the revision from one of the predefined parameters.

Can TeamCity read an MSBuild property from what gets checked out so I can combine it with the predefined property during the build? Can someone point me to a tutorial?

5 comments
Comment actions Permalink

Hi,

TeamCity updates assembly version at the start of the build. When you pass the parameter from MSBuild it is resolved after AssemblyInfoPatcher updated version.
What is you use case, wouldn't it be an option to set version as TeamCity parameter?

0
Comment actions Permalink

I would rather have the developer specify the major.minor.build when checking in the code and have the source control system supply the last .revision. So my MSBuild task sets a TeamCity variable named Sedona.BuildNumber, but this varialbe is not available to AssemblyInfoPatcher:

  <!-- Sets Sedona.BuildNumber in TeamCity -->

  <Target Name="ReadAssemblyVersion">

    <ReadLinesFromFile File="Properties\AssemblyInfo.cs">

      <Output TaskParameter="Lines"

              ItemName="ItemsFromFile"/>

    </ReadLinesFromFile>

    <PropertyGroup>

      <ReadAssemblyVersionPattern>\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+)</ReadAssemblyVersionPattern>

      <ReadAssemblyVersionIn>@(ItemsFromFile)</ReadAssemblyVersionIn>

      <ReadAssemblyVersionOut>$([System.Text.RegularExpressions.Regex]::Match($(ReadAssemblyVersionIn), $(ReadAssemblyVersionPattern)))</ReadAssemblyVersionOut>

      <ReadAssemblyVersionValue>$(ReadAssemblyVersionOut.Remove(0, 28))</ReadAssemblyVersionValue>

    </PropertyGroup>

  </Target>


  <Target Name="InitializeSedonaBuildNumber" DependsOnTargets="ReadAssemblyVersion">

    <Message Text="##teamcity[setParameter name='Sedona.BuildNumber' value='$(ReadAssemblyVersionValue)']" />

  </Target>

  <!-- Sets Sedona.BuildNumber in TeamCity -->

0
Comment actions Permalink

We have the same requirement.
Use Major.Minor.Patch from assembly file and add buildnumber using AssemblyInfoPatcher.

It would be mighty convenient if AssemblyInfoPatcher would make use of aterix placeholders like:

*.*.*.%build.number%

0
Comment actions Permalink

As I wrote in previous comment AssemblyInfo Patcher is started before build runners. So it does not know you changed the property.

The workaround is to add another build configuration and make snapshot dependency to current build configuration. You may specify build number as %deb.btID.build.number%, where btID is the build configuration ID of the new configuration.

0

Please sign in to leave a comment.