How can I determine which operating system my .NET Core app is running on?
In the past I could use Environment.OSVersion
.
What is the current way to determine whether my app is running on Mac or Windows?
NET on Android, Apple, Linux, and Windows operating systems. It can be used on Arm64, x64, and x86 architectures. It's also supported in emulated environments, like macOS Rosetta 2. New versions of .
Here by dependencies one can determine about the type of project.. NET Core application do reference Microsoft. NETCore. App (either as "type": "platform" for portable apps or without it for self-contained apps).
SharpOS is a discontinued computer operating system based on the . NET Framework and related programming language C#.
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform()
OSPlatform.Windows
OSPlatform.OSX
OSPlatform.Linux
bool isWindows = System.Runtime.InteropServices.RuntimeInformation
.IsOSPlatform(OSPlatform.Windows);
Thanks to the comment by Oleksii Vynnychenko
You can get the operating systems name and version as a string using
var osNameAndVersion = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
E.g. osNameAndVersion
would be Microsoft Windows 10.0.10586
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With