#nullable enable using System; using System.IO; using System.Reflection; namespace T3.Core.Compilation; /// /// Common info container for package loading and versioning, and the source of truth for /// whether this build is a prerelease — see . /// public static class RuntimeAssemblies { public const string NetVersion = "10.0"; // Static field initialisers run in source order — every public field below depends on // _coreAssembly, so it must be declared first. private static readonly Assembly _coreAssembly = typeof(RuntimeAssemblies).Assembly; public static readonly string CoreDirectory = Path.GetDirectoryName(_coreAssembly.Location)!; /// 4-part numeric assembly version (e.g. 4.2.0.2). Excludes any semver prerelease segment. public static readonly Version Version = _coreAssembly.GetName().Version!; /// /// Prerelease segment of the semver — empty for stable builds, "alpha" (or a future /// "beta.2", "rc.1") for prerelease builds. /// public static readonly string VersionSuffix = ParseVersionSuffix(); /// /// True for any prerelease build. Permissive on purpose so future beta / rc /// cycles get the same isolation without a code change. /// public static readonly bool IsPreview = !string.IsNullOrEmpty(VersionSuffix); public static readonly bool IsAlpha = !string.IsNullOrEmpty(VersionSuffix) && string.Equals(VersionSuffix, "alpha", StringComparison.Ordinal); /// /// Version formatted as semver without commit SHA — e.g. "4.2.0.2-alpha" or "4.2.0.2". /// public static readonly string FormattedVersion = string.IsNullOrEmpty(VersionSuffix) ? Version.ToString() : $"{Version}-{VersionSuffix}"; /// /// Reads the prerelease segment from . /// The informational version is "<numeric>[-<suffix>][+<sha>]"; we want /// everything between the first - and the optional +. /// private static string ParseVersionSuffix() { var informational = _coreAssembly .GetCustomAttribute() ?.InformationalVersion; if (string.IsNullOrEmpty(informational)) return string.Empty; var plusIndex = informational.IndexOf('+'); var withoutSha = plusIndex >= 0 ? informational[..plusIndex] : informational; var dashIndex = withoutSha.IndexOf('-'); if (dashIndex < 0 || dashIndex == withoutSha.Length - 1) return string.Empty; return withoutSha[(dashIndex + 1)..]; } }