-
Notifications
You must be signed in to change notification settings - Fork 467
Expand file tree
/
Copy pathAssembleyExtensions.cs
More file actions
47 lines (38 loc) · 1.73 KB
/
AssembleyExtensions.cs
File metadata and controls
47 lines (38 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using System.Linq;
using System.Reflection;
namespace Azure.Functions.Cli.Extensions
{
internal static class AssemblyExtensions
{
public static string GetInformationalVersion(this Assembly assembly)
{
var informationalVersion = assembly
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)
.OfType<AssemblyInformationalVersionAttribute>()
.FirstOrDefault()?.InformationalVersion;
return informationalVersion ?? string.Empty;
}
public static string GetCliVersion(this Assembly assembly)
{
// The package version is stamped into the assembly's AssemblyInformationalVersionAttribute at build time, followed by a '+'
// and the commit hash, e.g.: "4.0.10000-dev+67bd99a8ce2ec3cf833f25c039f60222caf44573 (64-bit)"
var version = assembly.GetInformationalVersion();
if (version is not null)
{
var plusIndex = version.IndexOf('+');
if (plusIndex > 0)
{
return version[..plusIndex];
}
return version;
}
// Fallback to the file version, which is based on the CI build number, and then fallback to the assembly version, which is
// product stable version, e.g. 4.0.0.0
version = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version
?? assembly.GetCustomAttribute<AssemblyVersionAttribute>()?.Version;
return version;
}
}
}