How to display application build time at runtime?

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

Guest

I am using VS.NET 2003 and C# to develop a Windows Forms application targeted
at Windows XP. I would like to automatically capture the build time and date
such that it can be displayed by the application, for example as part of the
About form.

Is there a way to configure VS.NET to capture this information and place it
in a variable or resource file such that it is available at runtime after
distribution?

Thanks,
Dave
 
I am using VS.NET 2003 and C# to develop a Windows Forms application
targeted at Windows XP. I would like to automatically capture the
build time and date such that it can be displayed by the application,
for example as part of the About form.

Is there a way to configure VS.NET to capture this information and
place it in a variable or resource file such that it is available at
runtime after distribution?

In general, something like this should work:

using System.Reflection;
using System.IO;

Assembly assembly = Assembly.GetExecutingAssembly();
FileInfo info = new FileInfo(assembly.Location);
Console.WriteLine(info.CreationTime);
 
Ryan,

Thanks for the suggestion, but the date being returned is much older than
the last build time. For example, I built and ran the code today (1/25/2005)
but the date returned was 12/22/2004. I am really looking for something
related to the time when the solution was built, not when an assembly might
have last been created or modified.

Thanks,
Dave
 
Hello Dave,

Assuming you are using the default versioning (1.0.*) in your assemblyinfo.cs
file, you can do something like this:

Version version = Assembly.GetExecutingAssembly().GetName().Version;
DateTime dt = new DateTime(2000, 1, 1);
dt.AddDays(version.Build);

version.Build is the number of days since 01.01.2000 and version.Revision
is 1/2 of the number of seconds since midnight.
 
Back
Top