Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Increment the build number automatically

I have two projects in solution. One is version 3.0.0.* and the other is 2.0.0.*. I build my solution on Team City using an MSBuild script. How can I inject the build number portion of the version string into the AssemblyVersion attribute leaving the major.minor.patch as defined at dev time.

To put it another way I want to manually control major.minor.patch (and the majors will differ across libs in the solution) but auto increment the build number.

like image 766
Myles McDonnell Avatar asked Jan 14 '23 13:01

Myles McDonnell


1 Answers

TeamCity will automatically manage the AssemblyVersion attributes for you, but there are a few caveats:

  1. It will totally overwrite the existing value.
  2. It will update all AssemblyVersions in the solution, so if you are tied to keeping different project versions in the same solution, this may not work for you.

With those caveats, here's how we've set it up:

  • In the General Settings of your build configuration, change the Build number format to %version%.{0}
  • In your Build Parameters define %version% as your major.minor.patch.
  • In your Build Steps, scroll to the bottom of the screen and click Add Build Feature. Select AssemblyInfo patcher. Make sure the Assembly version format is filled in as %build.number%.

And that's it. TeamCity will update all your assembly infos to major.minor.patch.build as defined by the %version% and build counter, and then automatically revert those changes as the very last step of the build.

like image 50
John Hoerr Avatar answered Jan 29 '23 01:01

John Hoerr