mirror of
https://github.com/bitwarden/server
synced 2025-12-29 14:43:39 +00:00
* Switch to using built in source link feature * Switch to using types assembly * Formatting * Make version retrieval safer * Add debug message * Apply suggestions from code review Co-authored-by: Matt Bishop <mbishop@bitwarden.com> --------- Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System.Diagnostics;
|
|
using System.Reflection;
|
|
|
|
namespace Bit.Core.Utilities;
|
|
|
|
public static class AssemblyHelpers
|
|
{
|
|
private static string? _version;
|
|
private static string? _gitHash;
|
|
|
|
static AssemblyHelpers()
|
|
{
|
|
var assemblyInformationalVersionAttribute = typeof(AssemblyHelpers).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
|
if (assemblyInformationalVersionAttribute == null)
|
|
{
|
|
Debug.Fail("The AssemblyInformationalVersionAttribute is expected to exist in this assembly, possibly its generation was turned off.");
|
|
return;
|
|
}
|
|
|
|
var informationalVersion = assemblyInformationalVersionAttribute.InformationalVersion.AsSpan();
|
|
|
|
if (!informationalVersion.TrySplitBy('+', out var version, out var gitHash))
|
|
{
|
|
// Treat the whole thing as the version
|
|
_version = informationalVersion.ToString();
|
|
return;
|
|
}
|
|
|
|
_version = version.ToString();
|
|
if (gitHash.Length < 8)
|
|
{
|
|
return;
|
|
}
|
|
_gitHash = gitHash[..8].ToString();
|
|
}
|
|
|
|
public static string? GetVersion()
|
|
{
|
|
return _version;
|
|
}
|
|
|
|
public static string? GetGitHash()
|
|
{
|
|
return _gitHash;
|
|
}
|
|
}
|