Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I automatically have the build date inserted at design time

Tags:

c#

.net

winforms

Hope fully the title was somewhat descriptive.

I have a winform application written in C# with .net 2.0. I would like to have the last compile date automatically updated to a variable for use in the about box and initial splash box. Currently I have a string variable that I update manually. Is there any way to do this?

VS2008 .net 2.0 c#

like image 441
Brad Avatar asked Dec 14 '09 21:12

Brad


1 Answers

Another trick (which you may not be able to use) is to leverage the automatic build and revision numbers generated by .NET. If your AssemblyInfo has:

[assembly: AssemblyVersion("1.0.*")]

The last two numbers are just a date/time stamp. Some code (list below) may help:

Version v = Assembly.GetExecutingAssembly().GetName().Version;
DateTime compileDate = new DateTime((v.Build - 1) * TimeSpan.TicksPerDay + v.Revision * TimeSpan.TicksPerSecond * 2).AddYears(1999);

Edit: here's an alternative answer that may be a little clearer to follow than what I put: https://stackoverflow.com/a/804895/2258

like image 163
Richard Morgan Avatar answered Oct 25 '22 03:10

Richard Morgan