11

I would like to put the date the application was built somewhere in the application. Say the about box. Any ideas how this can be done? I need to do this for C# but I am also looking for a general idea, so you can answer this for any specific language other than C#.

Nikhil
  • 2,230
  • 6
  • 33
  • 51

4 Answers4

20

Typically we just go with the executable's last modify date. This will be set when the exe is built and usually never changes (short of someone actually editing the file). When the file is installed, copied, moved, etc, Windows doesn't change that value.

DateTime buildDate = 
   new FileInfo(Assembly.GetExecutingAssembly().Location).LastWriteTime;

We use this technique for the about dialogs in our C# and C++ apps.

BadCanyon
  • 3,005
  • 19
  • 17
  • 8
    If you're working with GAC assemblies, this will return when this assembly was installed. – Rubens Farias May 25 '12 at 22:21
  • `FileInfo` also has a `CreationTime` property. Would that be better or worse or the same as using `LastWriteTime`? – shoelzer Feb 06 '19 at 21:37
  • I can answer my own question: 'LastWriteTime' is better. Basically, `CreationTime` is when the file was created and `LastWriteTime` is when the contents last changed. See https://stackoverflow.com/a/10277765/1339280 – shoelzer Feb 06 '19 at 21:46
15

The third number of the assembly version is a julian date with 0=1 Jan 2000 if you're using [assembly: AssemblyVersion("1.0.*")]

e.g.

DateTime buildDate = new DateTime(2000,1,1).AddDays(
  System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build
 );
Nikhil Agrawal
  • 47,018
  • 22
  • 121
  • 208
KristoferA
  • 12,287
  • 1
  • 40
  • 62
  • And, how/where exactly do you do that, practically? "*" is not allowed in the normal Assembly Information field in the project properties. – Nyerguds Feb 10 '14 at 08:08
  • 1
    Ah, never mind. It accepts "*" as third value in the properties dialog if the last field is left empty. Thanks for this. On a related note, the fourth field (Revision) is the time stamp, but it has to be multiplied by 2 before it can be used for AddSeconds(). – Nyerguds Feb 10 '14 at 08:37
2

You should be using version control - Subversion is free. Then you could include a number from the version control system that would unambiguously identify the source code used to build the app. A date won't do that. There are other advantages too.

  • Full history of all changes to the project.
  • Work seamlessly with other developers on the same project.

EDIT: Nikhil is already doing all this. But for some incomprehensible reason he has been told to include the date as well. I'm going to leave this answer here anyway, for future readers of this question.

Community
  • 1
  • 1
MarkJ
  • 30,070
  • 5
  • 68
  • 111
  • That's exactly what I explained, the revision number is all you need, which is exactly what we have right now. But for some reason I cannot understand, I have been told to include the exact date and time the app was built. – Nikhil Mar 05 '09 at 08:52
  • This is not relevant to the question but is good general advice. – Nikhil Mar 05 '09 at 08:53
0

There are usually keywords in your source code control system for this sort of thing.

Otherwise, look at including the date and time in the version number, or simply creating a small source code file which contains the date and time, and gets included in the build

Matthew Farwell
  • 60,889
  • 18
  • 128
  • 171