-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
I have frequently used RuntimeInformation. It is a great type and I'm glad we have it. At some point, I stopped using RuntimeInformation.OSDescription on Linux since it returns values that are not very useful.
That's for two reasons:
- It reports kernel information.
- For containers, the kernel is the host kernel.
Let's run this program
using System.Runtime.InteropServices;
Console.WriteLine(RuntimeInformation.OSDescription);Bare metal (Raspberry Pi OS):
$ dotnet run
Linux 5.15.84-v8+ #1613 SMP PREEMPT Thu Jan 5 12:03:08 GMT 2023
$ cat /etc/os-release | head -n 1
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"WSL + Containers (Debian):
$ dotnet run
Linux 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023
$ cat /etc/os-release | head -n 1
PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"Cloud (Azure + Ubuntu):
$ dotnet run
Linux 5.15.0-1034-azure #41-Ubuntu SMP Fri Feb 10 19:59:55 UTC 2023
$ cat /etc/os-release | head -n 1
PRETTY_NAME="Ubuntu 22.04.2 LTS"You can see which uname variant we use:
$ uname -srv
Linux 5.15.0-1034-azure #41-Ubuntu SMP Fri Feb 10 19:59:55 UTC 2023Windows:
>dotnet run
Microsoft Windows 10.0.22621macOS:
% dotnet run
Darwin 22.4.0 Darwin Kernel Version 22.4.0: Wed Feb 22 22:16:19 PST 2023; root:xnu-8796.100.763.505.1~1/RELEASE_ARM64_T8103I'd argue that the Linux kernel information serves no general purpose since the kernel is not the most important data for programs to know. For example, if containers are logging information, the kernel version is likely not the most important datapoint. Userland is likely much more important.
I propose two changes:
- Change
OSDescriptionto report information about the userland OS, which would mean rely on/etc/os-releaseon Linux (if present). - Consider adding a
KernelDescriptionproperty to report the currently provided kernel information.
The RuntimeInformation.OSDescription docs state the following:
Gets a string that describes the operating system on which the app is running.
I'd suggest that this is inaccurate. For containers, for example, Debian, Ubuntu, Alpine, and others all return the same value.
I made these changes quite some time ago, but they are telling: