-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
DotnetVersionFile.cs
70 lines (60 loc) · 2.11 KB
/
DotnetVersionFile.cs
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.DotNet.Cli.Utils
{
internal class DotnetVersionFile
{
public bool Exists { get; init; }
public string CommitSha { get; init; }
public string BuildNumber { get; init; }
public string FullNugetVersion { get; init; }
public string SdkFeatureBand { get; init; }
/// <summary>
/// The runtime identifier (rid) that this CLI was built for.
/// </summary>
/// <remarks>
/// This is different than RuntimeInformation.RuntimeIdentifier because the
/// BuildRid is a RID that is guaranteed to exist and works on the current machine. The
/// RuntimeInformation.RuntimeIdentifier may be for a new version of the OS that
/// doesn't have full support yet.
/// </remarks>
public string BuildRid { get; init; }
public DotnetVersionFile(string versionFilePath)
{
Exists = File.Exists(versionFilePath);
if (Exists)
{
IEnumerable<string> lines = File.ReadLines(versionFilePath);
int index = 0;
foreach (string line in lines)
{
if (index == 0)
{
CommitSha = line.Substring(0, 10);
}
else if (index == 1)
{
BuildNumber = line;
}
else if (index == 2)
{
BuildRid = line;
}
else if (index == 3)
{
FullNugetVersion = line;
}
else if (index == 4)
{
SdkFeatureBand = line;
}
else
{
break;
}
index++;
}
}
}
}
}