Loren Halvorson's Blog

If your only tool is a hammer...

A better way to set the version into the VersionInfo.cs file

In my previous post I mentioned that I had written my own <setversion> task to set the file version number in the centralized VersionInfo.cs. I took another look at NAnt's built in tasks, and <asminfo> does exactly what I need. I just changed the NAnt build script to write out VersionInfo.cs like this:

  <asminfo output="VersionInfo.cs" language="CSharp">
    <imports>
      <import name="System.Reflection" />
    </imports>
    <attributes>
      <attribute type="AssemblyFileVersionAttribute" value="${label-to-apply}" />
    </attributes>
  </asminfo>

Which writes out:

using System.Reflection;

//------------------------------------------------------------------------------
// <autogenerated>
//     This code was generated by a tool.
//     Runtime Version: 1.1.4322.573
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </autogenerated>
//------------------------------------------------------------------------------

[assembly: AssemblyFileVersionAttribute("1.0.0.123")]

Perfect. I love throwing away my own custom code in favor of built-in stuff!

Comments

TrackBack said:

If you aren't automating your build procedure, now is the time to start
# September 23, 2004 6:51 AM

Marc said:

Hey there,
I blogged about the same thing just a little while ago too!
http://bitarray.co.uk/marc/archive/2004/08/17/273.aspx

Cheers!
# September 27, 2004 9:19 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)