Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# get program version

private static DateTime GetLinkerTimestampUtc(Assembly assembly)
{
  var location = assembly.Location;
  return GetLinkerTimestampUtc(location);
}

private static DateTime GetLinkerTimestampUtc(string filePath)
{
  const int peHeaderOffset = 60;
  const int linkerTimestampOffset = 8;
  var bytes = new byte[2048];

  using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
  {
    file.Read(bytes, 0, bytes.Length);
  }

  var headerPos = BitConverter.ToInt32(bytes, peHeaderOffset);
  var secondsSince1970 = BitConverter.ToInt32(bytes, headerPos + linkerTimestampOffset);
  var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
  return  DateTime.Parse(dt.AddSeconds(secondsSince1970).ToString()).ToLocalTime();
}

public static String GetReleaseVersion()
{
  return String.Format("{0} {1}", Assembly.GetExecutingAssembly().GetName().Version.ToString(), GetLinkerTimestampUtc(Assembly.GetExecutingAssembly()));
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# insert today datetime 
Csharp :: dynamics 365 create record c# 
Csharp :: c# odp.net close session 
Csharp :: avoid writing the name of the type twice 
Csharp :: <link rel="stylesheet" href="styles/kendo.common.min.css" / 
Csharp :: c# ping all machines on local network 
Csharp :: Unity Scene Load by BuildIndex 
Csharp :: optional parameter get request c# 
Csharp :: c# ilogger for inherited class 
Csharp :: wpf mvvm crud example 
Csharp :: core ui switch 
Csharp :: c# execute after delay 
Csharp :: "using" c# 
Csharp :: delegate 
Csharp :: index sort 
Csharp :: c# get error message from cmd command 
Csharp :: c# bitwise and 
Csharp :: crystal report error webconfig reference 
Csharp :: nodatime instant to datetime off set c# 
Csharp :: finding holydays asp.net 
Csharp :: c# linq query map to entity 
Csharp :: jittery movement unity 
Csharp :: blazor data annotation diaply name 
Csharp :: #StopRape 
Csharp :: how to detect when a gameobject has exited a trigger c# 
Csharp :: search list for words c# 
Csharp :: dictionary and generic class c# 
Csharp :: querstring fromat asp.net c# 
Csharp :: asp.net mvc select from many to many relationship 
Csharp :: how to make soft body OBJECT in unity 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =