I need the date of compilation to be somehow hard coded in the code .
How i can do that thing ?
Thanks
I need the date of compilation to be somehow hard coded in the code .
How i can do that thing ?
Thanks
 
    
    In most of my Projects i use a function 'RetrieveLinkerTimestamp'.
        public DateTime RetrieveLinkerTimestamp(string filePath)
    {
        const int PeHeaderOffset = 60;
        const int LinkerTimestampOffset = 8;
        byte[] b = new byte[2048];
        Stream s = Stream.Null;
        try
        {
            s = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            s.Read(b, 0, 2048);
        }
        finally
        {
            if ((s != null)) s.Close();
        }
        int i = BitConverter.ToInt32(b, PeHeaderOffset);
        int SecondsSince1970 = BitConverter.ToInt32(b, i + LinkerTimestampOffset);
        DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
        dt = dt.AddSeconds(SecondsSince1970);
        dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
        return dt;
    }
maybe this is of help?
cheers,
Christian
 
    
    You could use a T4 template to generate your code wherever you need meta-information like this.
<#@ assembly name="System.Core.dll" #>
<#@ template language="C#v3.5" debug="True" hostspecific="True"  #>
<#@ output extension=".cs" #>
using System;
namespace MyNamespace
{
    public class MyClass
    {
        // <#= DateTime.Now.ToString() #>
    }
}
That template will output a class file that looks like:
using System;
namespace MyNamespace
{
    public class MyClass
    {
        // 2/9/2010 11:06:59 PM
    }
}
You might need to add a build task or a pre-build step to run the T4 compiler on every build.
Source control or Continuious integration build server? not exactly compile time and in code, but it gets a commit time and build number.
 
    
    There's probably nothing built into the language like this but you may find the following link helpful. How do I find the current time and date at compilation time in .net/C# application?