This article is a mirror article of machine translation, please click here to jump to the original article.

View: 33679|Reply: 1

[.NET Core] .NET Core determines the current operating system

[Copy link]
Posted on 11/13/2019 3:55:22 PM | | | |

.NET core is Microsoft's cross-platform framework that runs on Windows Linux osx operating system, and sometimes, we need to perform corresponding operations according to the current operation.

So how to judge the current operating system?

Introduce the package System.Runtime.InteropServices via nuget

Get information about your current operating system

Linux 4.9.184-linuxkit #1 SMP Tue Jul 2 22:58:16 UTC 2019
With this assembly we can obtain the operating system of the host environment of our program, currently there are three options: WIN, LIUNX, OSX

There is a RuntimeInformation.IsOSPlatform in this namespace that is used to determine the operating system

RuntimeInformation.IsOSPlatform(OSPlatform.Linux)// Determine whether it is Liunx

RuntimeInformation.IsOSPlatform(OSPlatform.Windows)/Determine whether it is Win

RuntimeInformation.IsOSPlatform(OSPlatform.OSX)/Determine whether it is OSX

The return values of the three methods are all bool values, which can be easily judged which operating system it is







Previous:Docker time inconsistencies, container time time zone setting
Next:Get rid of dead wages, 70 platforms for side hustles
Posted on 4/8/2022 1:46:38 PM |
Thanks for the answer
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com