确定.NET Core中的操作系统 [英] Determine Operating System in .NET Core
本文介绍了确定.NET Core中的操作系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何确定.NET Core应用程序在哪个操作系统上运行?
过去我可以使用 Environment.OSVersion
。
How can I determine which operating system my .NET Core app is running on?
In the past I could use Environment.OSVersion
.
当前确定方法是否是我的应用程序是在Mac还是Windows上运行?
What is the current way to determine whether my app is running on Mac or Windows?
推荐答案
方法
Method
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform()
可能参数
Possible Argument
OSPlatform.Windows
OSPlatform.OSX
OSPlatform.Linux
示例
Example
bool isWindows = System.Runtime.InteropServices.RuntimeInformation
.IsOSPlatform(OSPlatform.Windows);
更新
感谢作者的评论Oleksii Vynnychenko
Update
Thanks to the comment by Oleksii Vynnychenko
您可以使用
var osNameAndVersion = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
例如 osNameAndVersion
将是 Microsoft Windows 10.0.10586
这篇关于确定.NET Core中的操作系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文