I was going through trying to figure out how to get the version number of our built assemblies from NAnt. We specify them using AssemblyInfo.cs, so the GetVersion tasks weren’t working for me. I found a post by Michael Flanakin which outlined his way of pulling the version number from a file.
That gave me an idea to just load the assembly dynamically and pull it out of the assembly info. Here’s what I’m using, suggestions are always welcome.
value="C:\MyProject\bin\Debug\MyProject.dll"/>
name="getversion"
description="Get the version number from the assembly">
Hey Cory,
Just out of curiosity, why do you need the version of the built assemblies? What do you do with it after you grab it?
I’m enjoying your blog. Keep up the great work!
Luke
Hi Luke,
We use it to then report to our QA team that a new build is available, and we also tag it in Subversion so that we have a revision history of what was built. I just didn’t want to bore you with those details. ;)
Thanks for the compliment!
Cory
I should follow up that the product we’re working on has major/minor revisions, like 1.42. In creating the build to ship for a minor revision, we might send it to QA two or three times.
What was happening was that it was getting confusing saying that a bug was fixed in the “latest” 42 build. As soon as I started running into that, I wanted to have autoincrementing numbers so we could identify that.
Since we’re doing autoincrementing, it made sense to notify us which builds were available and to tag them so we had a history. Right now when a build is succesful NAnt zips it up and drops it on an FTP server. With this, we can tag it in Subversion and drop it on the FTP server with the build number attached.
I should say that the way to get the autogenerated numbers is by defining the build number portion of the versionumber in AssemblyInfo.cs with a *. So, for example, we’d set our next release of one of our products to be 1.43.0.* in AssemblyInfo.cs, which then sets the * to an autogenerated number every build.
Cool. We also do autoincrementing builds, but use the nant (or is it nantcontrib?) version task to do it. At the root of our project, we have a VersionInfo.txt project. It contains the last build number. Before compiling the app, our nant script reads this file and increments according to our rules, then writes a VersionInfo.cs file to disk. Think of it like an AssemblyInfo.cs file but with only the version attribute. That VersionInfo.cs file is included in each of the solution’s projects as a linked file, so when the nant script builds the solution, they all have the updated version number.
With this approach, there’s no need to reflect the assembly because you’ve defined the version number up front and the script has access to it for the entire run.
Not that there’s anything wrong with your approach, just figured I’d share an alternative path.
Luke
Hi cory,
What i
Hi cory ,
Tell me how i can use nant to get the version no. of a dll including major.minor.build.revision and then increment the required field of my choice, say minor alone and update it back to the assemblyinfo.cs file.
Thanks ,
Ranjith