Soo Wei Tan Soo Wei Tan - 1 year ago 272
C# Question

Equivalent of __DATE__, __TIME__ macros in C#

Is there an equivalent of

in C#?

Basically what I'm trying to do is place some build timestamping in a C# application.

One possibility I saw on Microsoft's website was to do the following:

Assembly assem = Assembly.GetExecutingAssembly();
Version vers = assem.GetName().Version;
DateTime buildDate = new DateTime(2000, 1, 1).AddDays(vers.Build).AddSeconds(vers.Revision * 2);

However, this only works if your version in AssemblyInfo.cs is "1.0..", which ours won't be.

Answer Source

I recommend customising your build script to write the date time into the file. The MSBuild Community Tasks project has a Time task that can be used for exactly this.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download