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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With