Make a C# program print its compilation date?

  • Thread starter Thread starter Michael A. Covington
  • Start date Start date
M

Michael A. Covington

Is there a way to make a C# program print the date on which it was compiled?

Finding the file date of the executable is one way, but it's not foolproof.

Thanks!
 
Not as far as I know. I had to solve it using the following elaborate
technic:

create a small program that reads the date and time using DateTime.Now and
serializes it into a small file. This program is exucute just before the
compilation of my main program. The generated serialized file is then
included in the application as an embedded resouce. Then in the program I
read this resource and deserialize to get the compilation date and time
back...

It's a lot of work, but ik works.
Hope this helps.
 
I saw somebody create a VS addin that sets the last two parts of the
assembly version to the date and time right before a build. I can't find it
now, but that would be another way (since you can pull up the assembly
version pretty easily in code). Plus it's kindof handy if you need to know
when you made a build just by looking at the version number of the .dll /
..exe

If I find it, I'll post a link here.

mike
 
Try creating a FileInfo object by specifying the filepath of the dll.
Then you can view the last modified date.

Greetz,
-- Rob.
 
[assembly:AssemblyFileVersion("1.0.*")]

This will change into an attribute where the 3rd part is the number of days
since Jan 1, 2000, and the 4th part is the number of seconds since midnight
(local time) divided by 2. This attribute can be accessed from the Assembly
object, or as the FileVersion looking at the Win32 file version resource.
 
Michael A. Covington said:
Grant Richins said:
[assembly:AssemblyFileVersion("1.0.*")]

This will change into an attribute where the 3rd part is the number of days
since Jan 1, 2000, and the 4th part is the number of seconds since midnight
(local time) divided by 2. This attribute can be accessed from the Assembly
object, or as the FileVersion looking at the Win32 file version
resource.

And for posterity, here is some working code. Thanks again!

private DateTime DateCompiled()

// 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.

{

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;
}
 
Back
Top