[ACCEPTED]-Compile date and time-reflection

Accepted answer
Score: 19

If you set the assembly version (usually 9 in AssemblyInfo.cs) to Major.Minor.* (e.g. 1.0.*), then you 8 can probably retrieve the build date at 7 runtime with something like this:

var version = Assembly.GetExecutingAssembly().GetName().Version;
DateTime buildDate = new DateTime(2000, 1, 1)
    .AddDays(version.Build)
    .AddSeconds(version.Revision*2);

When using 6 a * for the third and fourth part of the 5 assembly version, then these two parts are 4 set automatically at compile time to the 3 following values:

  • third part is the number of days since 2000-01-01
  • fourth part is the number of seconds since midnight divided by two (although some MSDN pages say it is a random number)

Oh, and you have to take 2 care of daylight saving time yourself (e.g. add 1 one hour if it's daylight saving time).

Score: 7

You can get it by this way:

File.GetLastWriteTime(Assembly.GetExecutingAssembly().Location);

Returns DateTime object.

0

Score: 2

What about:

new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;

0

More Related questions