Displaying Assembly Version Information

On a lot of my websites, I find it very useful to know exactly what version I’m working with.  Not only the version number, but also whether or not it’s running in RELEASE or DEBUG mode.

To accomplish this, it’s a fairly simple process.  Just put a Label control on your webform and then set the text property of it.  Here’s some sample code.

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim strVersion As String = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()

#If DEBUG Then
    lblVersion.Text = (String.Format("<span align=""center"" style=""width:100%;text-align:center;background-color:red;color:yellow;"">&nbsp;&nbsp;&nbsp;&nbsp;DEBUG MODE - {0}&nbsp;&nbsp;&nbsp;&nbsp;</span>", strVersion))
    lblVersion.Text = (String.Format("<span align=""center"" style=""width:100%;text-align:center;color:silver;font-size:8pt;"">{0}</span>", strVersion))
#End If

End Sub

The problem I was running into is that the version number was not automatically incrementing.  I did a little searching and found that I should update a file called AssemblyInfo.vb.

A quick look through my solution showed that I didn’t have that file.  I found the area where the data is contained though.  It’s in the project properties.  Specifically on the “Application” tab.

Click the “Assembly Information” button to get the following dialog.

Notice the “Assembly Version” is set to  This is why the version number is fixed.  There’s no option there to set things to auto-increment though.

According to the information I found, I should be able to replace some values with wildcards (asterisks) to get them to automatically increment.  Since I want the Build and the Revision to display the automatic values, I replaced the zeroes with asterisks.

BUZZ…. no dice.  I got the following error message.

It was easy enough to get around this to display the updated revision number.  Just set the build back to a fixed value.

Close… but I don’t want to have to remember to update the build manually everytime I build and deploy.  How to get both the build and the revision to show the automatic values?

A closer look at the error message shows the key.  It’s not very clear but if you put an asterisk in the build field and leave the revision field blank, you’ll get the results you’re after.


Incidently, the revision value is “ticks” since midnight of the current day.  The “build” value is the number of days since January 1, 2000.  Using these two values together, you can get a very precise timestamp of your build.



Here’s the quick one liner to copy and paste for C#

 string strVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

Update 2 – Displaying the build date

This was originally published on August 2, 2010.  Here it is January 29, 2018 and I’m still finding this article as handy as ever.

I have found over the course of time that it’s handy to display the build date and time as well as the version information.  By following the instructions at this StackOverflow post, it makes it as easy as can be:

Basically, you create an extension method that lives inside your class like this:

public static DateTime GetLinkerTime(this Assembly assembly, TimeZoneInfo target = null)
    var filePath = assembly.Location;
    const int c_PeHeaderOffset = 60;
    const int c_LinkerTimestampOffset = 8;

    var buffer = new byte[2048];

    using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
        stream.Read(buffer, 0, 2048);

    var offset = BitConverter.ToInt32(buffer, c_PeHeaderOffset);
    var secondsSince1970 = BitConverter.ToInt32(buffer, offset + c_LinkerTimestampOffset);
    var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

    var linkTimeUtc = epoch.AddSeconds(secondsSince1970);

    var tz = target ?? TimeZoneInfo.Local;
    var localTime = TimeZoneInfo.ConvertTimeFromUtc(linkTimeUtc, tz);

    return localTime;

then it’s a super simple matter of using it like this:

var linkTimeLocal = Assembly.GetExecutingAssembly().GetLinkerTime();
Scroll To Top