0

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?
Shog9
  • 156,901
  • 35
  • 231
  • 235
  • Rich, do me a favor and leave my posts alone? –  Jun 11 '09 at 15:52
  • Please see: http://stackoverflow.com/questions/175256/what-is-the-best-way-to-use-assembly-versioning-attributes ... and ... http://stackoverflow.com/questions/199823/best-practices-for-assembly-naming-and-versioning – Shog9 Jun 11 '09 at 16:13

4 Answers4

4

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
  • 414,610
  • 91
  • 852
  • 789
1

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.

CodeLikeBeaker
  • 20,682
  • 14
  • 79
  • 108
David Yancey
  • 2,020
  • 1
  • 16
  • 21
1

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
  • 9,552
  • 4
  • 50
  • 78
0

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

Community
  • 1
  • 1
Cheeso
  • 189,189
  • 101
  • 473
  • 713