in

dotNetFreak

Ramblings & Controls from a .NET Addicted Freak!

Kevin Gearing's Blog

Determining the Build Date of an Assembly

Sometimes it can be quite handy to display the build date of an assembly in an 'About' window or similar. After reading a couple of threads on how it can be calculated from the build and revision numbers, below is a very simple function to produce the build date for the currently executing assembly.

This ONLY works if the assembly was built using VS.NET and the assembly version attribute is set to something like the below. The asterisk (*) is the important part, as if present, VS.NET generates both the build and revision numbers automatically.

<Assembly: AssemblyVersion("1.0.*")>

The code...

Private Function BuildDate() As Date

'Build dates start from 01/01/2000

Dim result As Date = #1/1/2000#

'Retrieve the version information from the assembly from which this code is being executed

Dim version As System.Version = System.Reflection.Assembly.GetExecutingAssembly.GetName.Version

'Add the number of days (build)

result.AddDays(version.Build)

'Add the number of seconds since midnight (revision) multiplied by 2

result.AddSeconds(version.Revision * 2)

'If we're currently in daylight saving time add an extra hour

If TimeZone.IsDaylightSavingTime(Now, TimeZone.CurrentTimeZone.GetDaylightChanges(Now.Year)) Then result.AddHours(1)

Return result

End Function

An alternative method is to simply read the last time the file was written, using something similar to:

Return System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly.Location)

Comments

 

Kevin Gearing said:

I've also noticed that with VS.NET, it seems that build/revisions are not incremented until you actually shut down VS and re-open.

i.e. if you build your app on Monday, leave the editor open until Tuesday and re-build it, the build + revision will not have changed.

Close down and re-open and then re-build and it will... Hmm...
July 20, 2004 6:21 PM
 

DotNetDev.org » Determine .NET Assembly Build Date said:

Pingback from  DotNetDev.org &raquo; Determine .NET Assembly Build Date

November 12, 2008 2:18 AM
 

Bite my bytes said:

Links of the Week #62 (week 48/2008)

November 30, 2008 10:04 PM
 

Zunanji viri said:

Development Application Architecture Visios Now Available C# - How to get Program Files (x86) on Vista

November 30, 2008 11:05 PM
 

Wes said:

Thanks for the tip :-) I did have to make a small change to the code to get it to work:

result.AddDays(version.Build)

to

result = result.AddDays(version.Build)

result.AddSeconds(version.Revision * 2)

to

result = result.AddSeconds(version.Revision * 2)

December 19, 2008 6:06 PM
 

Music To Make Games By… » XNA/C# : Retrieval of Date and Time a Game Was Built said:

Pingback from  Music To Make Games By&#8230; &raquo; XNA/C# : Retrieval of Date and Time a Game Was Built

February 8, 2009 10:15 PM
 

Casey said:

This post was very helpful, thanks for posting it. I did this in Silverlight and as such didn't have access to TimeZone. Here's how I did it in case anyone is trying to do this in Silverlight/C#:

private DateTime BuildDate()

{

   DateTime date = new DateTime(2000, 1, 1);

   string[] parts = Assembly.GetExecutingAssembly().FullName.Split(',');

   string[] versionParts = parts[1].Split('.');

   date = date.AddDays(Int32.Parse(versionParts[2]));

   date = date.AddSeconds(Int32.Parse(versionParts[3]) * 2);

   if (System.TimeZoneInfo.Local.IsDaylightSavingTime(date))

   {

       date = date.AddHours(1);

   }

   return date;

}

May 6, 2009 6:25 PM
 

Determine .NET Assembly Build Date « Srsbsns said:

Pingback from  Determine .NET Assembly Build Date &laquo;  Srsbsns

June 22, 2009 6:57 AM
 

Peter Holpar said:

Thanks for the algorithm! See the link below for a simple WPF-based utility that applies it in practice to make the conversion between version number and build date: pholpar.wordpress.com/.../how-to-get-the-assembly-version-number-from-the-build-date-and-vice-versa

Peter

January 28, 2011 11:49 PM
 

Peter Holpar said:

Thanks for the algorithm! See the link below for a simple WPF-based utility that applies it in practice to make the conversion between version number and build date: pholpar.wordpress.com/.../how-to-get-the-assembly-version-number-from-the-build-date-and-vice-versa

Peter

January 28, 2011 11:50 PM
 

zia said:

Hi,

thank you for good idea, better than AddHour(1) would be:

DaylightTime dlt = TimeZone.CurrentTimeZone.GetDaylightChanges(result.Year);

if (TimeZone.IsDaylightSavingTime(built, dlt)) result= result.Add(dlt.Delta);

May 26, 2011 12:49 PM
 

Jim Moore said:

Thanks for the effort.  You made it easier for me.  Even 9 years later.

April 24, 2013 4:58 PM

Leave a Comment

(required)  
(optional)
(required)  

Protected by FormShield
Refresh
Listen
Please enter the characters shown on the image


Code:


Add
Copyright ©2004-2007 Kevin Gearing. All Rights Reserved.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems