mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-04-03 07:58:01 +02:00
31 lines
896 B
C#
31 lines
896 B
C#
using System.Reflection;
|
|
|
|
namespace VoidCat.Model;
|
|
|
|
public class BuildInfo
|
|
{
|
|
public string? Version { get; init; }
|
|
public string? GitHash { get; init; }
|
|
public DateTime BuildTime { get; init; }
|
|
|
|
public static BuildInfo GetBuildInfo()
|
|
{
|
|
var asm = Assembly.GetEntryAssembly();
|
|
var version = asm.GetName().Version;
|
|
|
|
var gitHash = asm
|
|
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
|
.FirstOrDefault(attr => attr.Key == "GitHash")?.Value;
|
|
|
|
var buildTime = asm
|
|
.GetCustomAttributes<AssemblyMetadataAttribute>()
|
|
.FirstOrDefault(attr => attr.Key == "BuildTime");
|
|
|
|
return new()
|
|
{
|
|
Version = $"{version.Major}.{version.Minor}.{version.Build}",
|
|
GitHash = gitHash,
|
|
BuildTime = DateTime.FromBinary(long.Parse(buildTime?.Value ?? "0"))
|
|
};
|
|
}
|
|
} |