public DateTime GetBuildDate(Assembly assembly)
{
var location = assembly.Location;
const int headerOffset = 60;
const int linkerTimestampOffset = 8;
var buffer = new byte[2048];
Stream stream = null;
try
{
stream = new FileStream(location, FileMode.Open, FileAccess.Read);
stream.Read(buffer, 0, 2048);
}
finally
{
if (stream != null)
{
stream.Close();
}
}
var i = BitConverter.ToInt32(buffer, headerOffset);
var secondsSince1970 = BitConverter.ToInt32(buffer, i + linkerTimestampOffset);
var dt = new DateTime(1970, 1, 1, 0, 0, 0);
dt = dt.AddSeconds(secondsSince1970);
dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
return dt;
}
Sample VB.NET
Public Function GetBuildDate(assembly as Assembly) As DateTime
Dim location = assembly.Location
Const headerOffset As Integer = 60
Const linkerTimestampOffset As Integer = 8
Dim buffer = New Byte(2047) {}
Dim stream As Stream = Nothing
Try
stream = New FileStream(location, FileMode.Open, FileAccess.Read)
stream.Read(buffer, 0, 2048)
Finally
If stream IsNot Nothing Then
stream.Close()
End If
End Try
Dim i = BitConverter.ToInt32(buffer, headerOffset)
Dim secondsSince1970 = BitConverter.ToInt32(buffer, i + linkerTimestampOffset)
Dim dt = New DateTime(1970, 1, 1, 0, 0, 0)
dt = dt.AddSeconds(secondsSince1970)
dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours)
Return dt
End Function
RT @CodeSnippetsNET: How to get the BuildDate of a Assembly http://t.co/bdx7ibfhxw #csharp #dotnet #vb #coding #code