Skip to content

Cory Foy

Organizational agility through intersecting business and technology

Menu
  • FASTER Fridays
  • Mapping Mondays
  • Player Embed
  • Search Videos
  • User Dashboard
  • User Videos
  • Video Category
  • Video Form
  • Video Tag
Menu

Get AssemblyInfo.cs version info from an Assembly using NAnt

Posted on November 17, 2005 by Cory Foy

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.

      name="build.assembly.filename"
    value="C:\MyProject\bin\Debug\MyProject.dll"/>
  
    name="getversion"
    description="Get the version number from the assembly">
    
    
  

7 thoughts on “Get AssemblyInfo.cs version info from an Assembly using NAnt”

  1. Luke Melia says:
    November 17, 2005 at 11:31 pm

    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

  2. Cory Foy says:
    November 18, 2005 at 8:53 am

    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

  3. Cory Foy says:
    November 18, 2005 at 8:59 am

    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.

  4. Cory Foy says:
    November 18, 2005 at 9:08 pm

    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.

  5. Luke Melia says:
    November 20, 2005 at 10:19 am

    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

  6. Anonymous says:
    December 26, 2005 at 4:48 am

    Hi cory,

    What i

  7. Anonymous says:
    December 26, 2005 at 4:50 am

    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

Comments are closed.

© 2025 Cory Foy | Powered by Superbs Personal Blog theme