// Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; using System.IO; namespace Microsoft.DotNet.Cli.Utils { internal class DotnetVersionFile { public bool Exists { get; set; } public string CommitSha { get; set; } public string BuildNumber { get; set; } /// /// The runtime identifier (rid) that this CLI was built for. /// /// /// This is different than RuntimeEnvironment.GetRuntimeIdentifier() because the /// BuildRid is a RID that is guaranteed to exist and works on the current machine. The /// RuntimeEnvironment.GetRuntimeIdentifier() may be for a new version of the OS that /// doesn't have full support yet. /// public string BuildRid { get; set; } public DotnetVersionFile(string versionFilePath) { Exists = File.Exists(versionFilePath); if (Exists) { IEnumerable 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 { break; } index++; } } } } }