Skip to content

Instantly share code, notes, and snippets.

@EgorBo
Created November 7, 2021 16:09
Show Gist options
  • Save EgorBo/6ea1c1cdf6240e595e3cd2a75e412503 to your computer and use it in GitHub Desktop.
Save EgorBo/6ea1c1cdf6240e595e3cd2a75e412503 to your computer and use it in GitHub Desktop.
dotnet-runtime-commit.cs
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Xml.Linq;
class Program
{
static void Main() => Console.WriteLine($"dotnet/runtime commit: {GetDotnetRuntimeCommit()}");
public static string GetDotnetRuntimeCommit()
{
var process = Process.Start(
new ProcessStartInfo
{
FileName = "dotnet",
Arguments = "--info",
RedirectStandardOutput = true,
UseShellExecute = false
});
string output = process!.StandardOutput.ReadToEnd();
process.WaitForExit();
string sdkCommit = Regex.Match(output, @"Commit: +(.\w+)").Groups[1].Value;
if (string.IsNullOrEmpty(sdkCommit))
throw new InvalidOperationException("'dotnet --info' returned an unexpected result:\n " + output);
var doc = XDocument.Load($"https://raw.githubusercontent.com/dotnet/installer/{sdkCommit}/eng/Version.Details.xml");
string dotnetRuntimeHash = doc.Root?
.Descendants("Dependency")
.FirstOrDefault(d => d.Attribute("Name")?.Value == "Microsoft.NETCore.Platforms")?
.Element("Sha")?.Value ?? "";
if (string.IsNullOrEmpty(dotnetRuntimeHash))
throw new InvalidOperationException("dotnet/runtime hash was not found.");
return dotnetRuntimeHash;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment