Profile picture Schedule a Meeting
c a n d l a n d . n e t

Setting build numbers with Nant

Dusty Candland | |

Setting build numbers with Nant

I wanted something that would update the version number of my builds from within Nant. I found that using some of the built in functions of Nant I could get what I wanted without too much work. Nothing really exciting here, but a couple of notes. First the version numbers stored in the meta data limit the size to uint16.maxvalue - 1 so the value must be less then 65534. As such I could not use the format yyyyMMdd as I wanted to, so I ended up using days since 1/1/2000. Secondly, when loading the file with loadfile I needed to mark the encoding as UTF-8 so that the file would be writen back out in a usable form. Anyway, here's the nant code I ended up using.
<property name="build.major" value="0"/>
<
property name="build.minor" value="9"/>
<
property name="build.build" value="${timespan::get-days(datetime::now() - datetime::parse('01/01/2000'))}"/>
<property name="build.revision" value="0"/>
<property name="build.version" value="${build.major}.${build.minor}.${build.build}.${build.revision}"/>
<foreach item="File" property="assemblyinfofile">
 <in>
 <items basedir="${project.root}">
 <include name="**\AssemblyInfo.cs"/>
 </items>
 </in>
 <do>
 <echo message="${path::get-file-name(assemblyinfofile)}"/>
 <loadfile file="${assemblyinfofile}"property="assemblyinfofile.content"encoding="utf-8"/>
 <regex pattern="&quot;(?'version'\d+.\d+.\d+.\d+|\d+.\d+.*)&quot;" input="${assemblyinfofile.content}"/>
 <echo file="${assemblyinfofile}">${string::replace(assemblyinfofile.content, version, build.version)}</echo>
 <echo message="-> Updated version from ${version} to ${build.version}"/>
 </do>
</foreach>

Webmentions

These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: