App version and build date?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Ive set up my application to read the build version from the <assembly> key
inside my Web.config file using:

string myver = Assembly.GetExecutingAssembly().GetName().Version().ToString()

Is there a way to get the DATE of the build as well?
 
Ive set up my application to read the build version from the said:
inside my Web.config file using:
string myver = Assembly.GetExecutingAssembly().GetName().Version().ToString()

Is there a way to get the DATE of the build as well?

You'd have to load the file in question (DLL or EXE) into a FileInfo
and get the creation date off it.

FileInfo oMyFile = new
FileInfo(Assembly.GetExecutingAssembly().Location);

DateTime oBuildDate = oMyFile.CreationTime;
(or possibly oMyFile.CreationTimeUtc; )

HTH
Marc
 
You'd have to load the file in question (DLL or EXE) into a FileInfo
and get the creation date off it.

When I deployed another version of assembly several minutes later to the
same place,
the creation time of the file was not changed (only modification time).

So I have used modification time instead.
 
JP said:
Ive set up my application to read the build version from the <assembly> key
inside my Web.config file using:

string myver = Assembly.GetExecutingAssembly().GetName().Version().ToString()

Is there a way to get the DATE of the build as well?

Here is sample code that retrieves build date from an assembly:

AssemblyName an = Assembly.GetEntryAssembly().GetName();
DateTime date = new DateTime(2000, 1, 1, 0, 0, 0);
date += TimeSpan.FromDays(an.Version.Build) +
TimeSpan.FromSeconds(an.Version.Revision * 2);

HTH

Michal Dabrowski
 
Here is sample code that retrieves build date from an assembly:
AssemblyName an = Assembly.GetEntryAssembly().GetName();
DateTime date = new DateTime(2000, 1, 1, 0, 0, 0);
date += TimeSpan.FromDays(an.Version.Build) +
TimeSpan.FromSeconds(an.Version.Revision * 2);

That *ONLY* works *IF* you *DO NOT* change your assembly version
numbering !

By default, the "build" portion of your assembly will indeed reflect
the build date - but you can change that, if you wish to! And then,
your method here will fail miserably......

Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 
Marc said:
That *ONLY* works *IF* you *DO NOT* change your assembly version
numbering !

That's true, sorry, forgot to mention this. One has to leave the two
asterisks at the end of assembly version number for this method to work.
By default, the "build" portion of your assembly will indeed reflect
the build date - but you can change that, if you wish to! And then,
your method here will fail miserably......

Yes, but looking at file creation date can also produce incorrect result
if the date is not preserved by all programs used between build and
deployment (although I think that most of them preserve it).

Best regards,
Michal Dabrowski
 
Back
Top