Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put the build date of application somewhere in the application?

Tags:

c#

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

like image 496
Nikhil Avatar asked Mar 05 '09 05:03

Nikhil


3 Answers

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
 );
like image 56
KristoferA Avatar answered Nov 20 '22 06:11

KristoferA


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.

like image 43
BadCanyon Avatar answered Nov 20 '22 05:11

BadCanyon


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.

like image 39
MarkJ Avatar answered Nov 20 '22 04:11

MarkJ