2

Is there any virable that gets the time of compilation in the .net environment ?

I am looking for something like __DATE__ in c++ , I need to put in my about window the time of code compilation .

Thanks

Night Walker
  • 20,638
  • 52
  • 151
  • 228

3 Answers3

2

There is no built-in way to do this.

However, you could make a pre-build step that writes the current time to a .cs file in a static readonly field.

EDIT: For example:

echo using System; > CompileTime.cs
echo namespace MyCompany.MyProduct { >> CompileTime.cs
echo     static class Compilation { >> CompileTime.cs
echo         public static readonly DateTime TimeStamp = DateTime.Parse("%date%%time%", System.Globalization.CultureInfo.InvariantCulture); >> CompileTime.cs
echo     } >> CompileTime.cs
echo } >> CompileTime.cs
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
2

Despite what others have answered, the short answer is Yes.

You can use the version format "1.0.*" for your assembly and the compiler will add the compilation date/time to the end of the version number string - which can easily be read from the ExecutingAssembly.

See here for details.

Community
  • 1
  • 1
Jason Williams
  • 56,972
  • 11
  • 108
  • 137
  • Most agile shops would have a version number where the revision of the VCS is written into the AssemblyInfo file as a pre-build step, and so this isn't feasible. Also, it really is a cheap hack as the OP meant something like: "Is there such a thing as 'Environment.CompileTime'" or similar. – Wim Dec 06 '09 at 13:54
  • I disagree. The OP asked if there is an option in the compiler that provides the date/time that an assembly is compiled, and there is - you can ask it to stamp this info into the version number. Other information (e.g. VCS revision) can easily be added in a different attribute if you require both pieces of information. – Jason Williams Dec 06 '09 at 17:12
-3

Short answer: no.

Think about it: time of compilation of what? Last compile? All compilations that have been performed in the last year?

You'll have to time this yourself. Elaborate on what you want to achieve, and people will be able to provide you with a better answer.

Wim
  • 11,998
  • 1
  • 34
  • 57