Skip to content

Instantly share code, notes, and snippets.

@AnalogFeelings
Created October 19, 2021 15:57
Show Gist options
  • Save AnalogFeelings/c1ef9deb28addf6ddb9c69700f96007e to your computer and use it in GitHub Desktop.
Save AnalogFeelings/c1ef9deb28addf6ddb9c69700f96007e to your computer and use it in GitHub Desktop.
(dotnetcore) Friendly OS Name
public string FriendlyOSName()
{
string osName = string.Empty;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Version version = Environment.OSVersion.Version;
switch (version.Major)
{
case 6:
osName = version.Minor switch
{
1 => "Windows 7",
2 => "Windows 8",
3 => "Windows 8.1",
_ => "Unknown Windows",
};
break;
case 10:
switch (version.Minor)
{
case 0:
if (version.Build >= 22000) osName = "Windows 11";
else osName = "Windows 10";
break;
default: osName = "Unknown Windows"; break;
}
break;
default:
osName = "Unknown Windows";
break;
}
}
else if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (File.Exists("/etc/issue.net"))
osName = File.ReadAllText("/etc/issue.net");
else
osName = "Linux";
}
return osName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment