确定 .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?
推荐答案
方法
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform()
可能的论据
OSPlatform.Windows
OSPlatform.OSX
OSPlatform.Linux
示例
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屋!
查看全文