添加编译日期为code [英] Adding compilation date to the code
本文介绍了添加编译日期为code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编译日期为不知何故很难codeD在code。
I need the date of compilation to be somehow hard coded in the code .
我如何能做到这一点的东西?
How i can do that thing ?
感谢
推荐答案
在我的大部分项目我使用功能'RetrieveLinkerTimestamp。
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?
欢呼声中,
基督教
这篇关于添加编译日期为code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文