| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Diagnostics; |
| | | 6 | | using System.Reflection; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Telemetry; |
| | | 9 | | |
| | | 10 | | internal static class AssemblyVersionExtensions |
| | | 11 | | { |
| | | 12 | | public static string GetPackageVersion(this Assembly assembly) |
| | | 13 | | { |
| | | 14 | | // MinVer https://github.com/adamralph/minver?tab=readme-ov-file#version-numbers |
| | | 15 | | // together with Microsoft.SourceLink.GitHub https://github.com/dotnet/sourcelink |
| | | 16 | | // fills AssemblyInformationalVersionAttribute by |
| | | 17 | | // {majorVersion}.{minorVersion}.{patchVersion}.{pre-release label}.{pre-release version}.{gitHeight}+{Git SHA o |
| | | 18 | | // Ex: 1.5.0-alpha.1.40+807f703e1b4d9874a92bd86d9f2d4ebe5b5d52e4 |
| | | 19 | | // The following parts are optional: pre-release label, pre-release version, git height, Git SHA of current comm |
| | | 20 | | // For package version, value of AssemblyInformationalVersionAttribute without commit hash is returned. |
| | | 21 | | |
| | 8 | 22 | | var informationalVersion = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVe |
| | | 23 | | Debug.Assert(!string.IsNullOrEmpty(informationalVersion), "AssemblyInformationalVersionAttribute was not found i |
| | | 24 | | |
| | 8 | 25 | | var indexOfPlusSign = informationalVersion.IndexOf('+'); |
| | | 26 | | |
| | 8 | 27 | | return indexOfPlusSign > 0 |
| | 8 | 28 | | ? informationalVersion.Substring(0, indexOfPlusSign) |
| | 8 | 29 | | : informationalVersion; |
| | | 30 | | } |
| | | 31 | | } |