This repository was archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathVersionHelper.cs
More file actions
44 lines (40 loc) · 1.61 KB
/
VersionHelper.cs
File metadata and controls
44 lines (40 loc) · 1.61 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
using System;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
namespace SPCode.Utils
{
public static class VersionHelper
{
public static Version GetAssemblyVersion()
{
return Assembly.GetEntryAssembly()?.GetName().Version;
}
public static string GetAssemblyInformationalVersion()
{
return ((AssemblyInformationalVersionAttribute)Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)
.FirstOrDefault()).InformationalVersion;
}
public static int GetRevisionNumber()
{
var revRegex = new Regex("(?<=beta)[0-9]*");
var attribute = (AssemblyInformationalVersionAttribute)Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault();
if (!revRegex.IsMatch(attribute.InformationalVersion))
{
throw new Exception("No match found for specified informational version.");
}
return int.Parse(revRegex.Match(attribute.InformationalVersion).ToString());
}
public static int GetRevisionNumber(string informationalVersion)
{
var revRegex = new Regex("(?<=beta)[0-9]*");
if (!revRegex.IsMatch(informationalVersion))
{
throw new Exception("No match found for specified informational version.");
}
return int.Parse(revRegex.Match(informationalVersion).ToString());
}
}
}