Tuesday, January 30, 2007

Determining the build date of a Managed executable/dll

// Assumes that in AssemblyInfo.cs, // the version is specified as 1.0.* or the like, // with only 2 numbers specified; // the next two are generated from the date. // This routine decodes them. private static DateTime DateCompiled() { System.Version v = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; // v.Build is days since Jan. 1, 2000 // v.Revision*2 is seconds since local midnight // (NEVER daylight saving time) DateTime t = new DateTime(v.Build * TimeSpan.TicksPerDay +v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999); return t; }

No comments: