views:

185

answers:

4

I am thinking of the following design:

static class AppVersion
{
     public static string BuildDate 
     {
       get; set;
     }
     public static string Version 
     {
       get; set;
     }
     public static string GetVersion 
     {
       get; set;
     }
}

A few questions on this:

  1. How can I get the build date?
  2. How can I print a date in a nice format?
  3. How can I obtain and print the Visual Studio version in a nice format?
  4. It is probably a bad idea to hard code the version into the binary, so I put the version into assembly information. How can I programmatically get it?
+4  A: 

I think your first questions are a matter of taste. You could use String.Format to get any style you want. Regarding your last question:

System.Reflection.Assembly.GetExecutingAssembly().Version

returns the version number of the current assembly and:

typeof(SomeTypeInSomeAssembly).Assembly.Version

will return the version number of the assembly containing the specific type.

Mehrdad Afshari
+1  A: 

For build Date look at http://dotnetfreak.co.uk/blog/archive/2004/07/08/determining-the-build-date-of-an-assembly.aspx

For the version / Get Version look at the System.Reflection.Assembly name space.

As for printing the date in a nice format, you'll want to either use the extension methods built off of DateTime class such as .ToShortDateString() or CultureInfo.

David Yancey
+1  A: 

We run all our production builds through CruiseControl.NET, which (among many other things) has the facility to version builds.

We then have a snippet of code that applies the CC.NET-generated build number (and other stuff) to AssemblyInfo.cs just before it's given to the compiler for building.

I suppose you could use a similar technique to insert the build date into a constant in some class somewhere in your app.

tomfanning
A: 

For build date or timestamp, you can embed it into the assembly when building.
For how to do that, see here.

Cheeso