How to display application build time at runtime?

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
 
R

Ryan Trudelle-Schwarz

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);
 
G

Guest

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
 
M

Matt Berther

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top