Setting build numbers with Nant
Dusty Candland |
|
<h3> Setting build numbers with Nant </h3> 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.<br /><pre class="csharpcode"><span class="kwrd"><</span><span class="html">property</span><span class="attr"> name</span><span class="kwrd">="build.major"</span><span class="attr"> value</span><span class="kwrd">="0"</span><span class="kwrd">/></span><span class="kwrd"><br /><</span><span class="html">property</span><span class="attr"> name</span><span class="kwrd">="build.minor"</span><span class="attr"> value</span><span class="kwrd">="9"</span><span class="kwrd">/></span><span class="kwrd"><br /><</span><span class="html">property</span><span class="attr"> name</span><span class="kwrd">="build.build"</span><span class="attr"> value</span><span class="kwrd">="${timespan::get-days(datetime::now() - datetime::parse('01/01/2000'))}"</span><span class="kwrd">/></span><br /><span class="kwrd"><</span><span class="html">property</span><span class="attr"> name</span><span class="kwrd">="build.revision"</span><span class="attr"> value</span><span class="kwrd">="0"</span><span class="kwrd">/></span><br /><span class="kwrd"><</span><span class="html">property</span><span class="attr"> name</span><span class="kwrd">="build.version"</span><span class="attr"> value</span><span class="kwrd">="${build.major}.${build.minor}.${build.build}.${build.revision}"</span><span class="kwrd">/></span><br /><span class="kwrd"><</span><span class="html">foreach</span><span class="attr"> item</span><span class="kwrd">="File"</span><span class="attr"> property</span><span class="kwrd">="assemblyinfofile"</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">in</span><span class="kwrd">><br /></span> <span class="kwrd"><</span><span class="html">items</span><span class="attr"> basedir</span><span class="kwrd">="${project.root}"</span><span class="kwrd">><br /></span> <span class="kwrd"><</span><span class="html">include</span><span class="attr"> name</span><span class="kwrd">="**\AssemblyInfo.cs"</span><span class="kwrd">/><br /></span> <span class="kwrd"></</span><span class="html">items</span><span class="kwrd">></span><br /> <span class="kwrd"></</span><span class="html">in</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">do</span><span class="kwrd">><br /></span> <span class="kwrd"><</span><span class="html">echo</span><span class="attr"> message</span><span class="kwrd">="${path::get-file-name(assemblyinfofile)}"</span><span class="kwrd">/><br /></span> <span class="kwrd"><</span><span class="html">loadfile </span><span class="attr">file</span><span class="kwrd">="${assemblyinfofile}"</span><span class="attr">property</span><span class="kwrd">="assemblyinfofile.content"</span><span class="attr">encoding</span><span class="kwrd">="utf-8"</span><span class="kwrd">/></span><br /> <span class="kwrd"><</span><span class="html">regex</span><span class="attr"> pattern</span><span class="kwrd">="&quot;(?'version'\d+\.\d+\.\d+\.\d+|\d+\.\d+\.\*)&quot;" </span><span class="attr">input</span><span class="kwrd">="${assemblyinfofile.content}"</span><span class="kwrd">/></span><br /> <span class="kwrd"><</span><span class="html">echo</span><span class="attr"> file</span><span class="kwrd">="${assemblyinfofile}"</span><span class="kwrd">></span>${string::replace(assemblyinfofile.content, version, build.version)}<span class="kwrd"></</span><span class="html">echo</span><span class="kwrd">></span><br /> <span class="kwrd"><</span><span class="html">echo</span><span class="attr"> message</span>="<span class="attr">-</span><span class="kwrd">></span> Updated version from ${version} to ${build.version}"<span class="kwrd">/><br /></span> <span class="kwrd"></</span><span class="html">do</span><span class="kwrd">></span><br /><span class="kwrd"></</span><span class="html">foreach</span><span class="kwrd">></span></pre><div style="clear: both; padding-bottom: 0.25em;"></div>
Webmentions
These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: