init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
64
Kreta.Core/KretaVersion.cs
Normal file
64
Kreta.Core/KretaVersion.cs
Normal file
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Kreta.Core
|
||||
{
|
||||
public sealed class KretaVersion
|
||||
{
|
||||
private KretaVersion()
|
||||
{
|
||||
}
|
||||
|
||||
private static readonly Lazy<VersionInfo> VersionInfo = new Lazy<VersionInfo>(GetVersionInfo);
|
||||
|
||||
public static VersionInfo Instance => VersionInfo.Value;
|
||||
|
||||
private static VersionInfo GetVersionInfo()
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
|
||||
string assemblyLocation = assembly.Location;
|
||||
|
||||
DateTime assemblyCreationDateTime = File.GetCreationTime(assemblyLocation);
|
||||
var result = new VersionInfo
|
||||
{
|
||||
AssemblyCreationDateTime = assemblyCreationDateTime
|
||||
};
|
||||
|
||||
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assemblyLocation);
|
||||
|
||||
string mainVersion = fileVersionInfo.FileVersion;
|
||||
if (!string.IsNullOrWhiteSpace(mainVersion))
|
||||
{
|
||||
result.MainVersion = mainVersion;
|
||||
}
|
||||
|
||||
int fileMajorPart = fileVersionInfo.FileMajorPart;
|
||||
int fileMinorPart = fileVersionInfo.FileMinorPart;
|
||||
if (fileMajorPart > 0 && fileMinorPart >= 0)
|
||||
{
|
||||
result.ShortMainVersion = $"{fileMajorPart}.{fileMinorPart}";
|
||||
}
|
||||
|
||||
List<AssemblyMetadataAttribute> customAttributes = assembly.GetCustomAttributes().OfType<AssemblyMetadataAttribute>().ToList();
|
||||
|
||||
string branchName = customAttributes.SingleOrDefault(x => x.Key == Constants.Version.BranchName)?.Value;
|
||||
if (!string.IsNullOrWhiteSpace(branchName))
|
||||
{
|
||||
result.BranchName = branchName;
|
||||
}
|
||||
|
||||
string commitNumber = customAttributes.SingleOrDefault(x => x.Key == Constants.Version.CommitNumber)?.Value;
|
||||
if (!string.IsNullOrWhiteSpace(commitNumber))
|
||||
{
|
||||
result.CommitNumber = commitNumber;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue