.NET 标准库 — 一个库统治他们.
.NET 标准库功能可能因运行它的 .NET 平台而异:
The .NET Standard Library functionality may vary depending on the .NET platform that runs it:
- .NET 框架
- .NET 核心
- Xamarin
如何查看 .NET Standard 库当前运行所在的 .NET 平台?
How to check the .NET platform where the .NET Standard library currently runs?
例如:
// System.AppContext.TargetFrameworkName // returns ".NETFramework,Version=v4.6.1" for .NET Framework // and // returns null for .NET Core. if (IsNullOrWhiteSpace(System.AppContext.TargetFrameworkName)) // the platform is .NET Core or at least not .NET Framework else // the platform is .NET Framework这是回答问题的可靠方法吗(至少对于 .NET Framework 和 .NET Core)?
Is it reliable way to answer the question (at least for .NET Framework and .NET Core)?
推荐答案使用 RuntimeInformation.FrameworkDescription 来自 System.Runtime.InteropServices 命名空间的属性.
Use the RuntimeInformation.FrameworkDescription Property from the System.Runtime.InteropServices namespace.
返回一个字符串,该字符串指示运行应用的 .NET 安装的名称.
Returns a string that indicates the name of the .NET installation on which an app is running.
该属性返回以下字符串之一:
The property returns one of the following strings:
.NET Core".
".NET Core".
.NET 框架".
.NET 原生".
更多推荐
如何确定运行.NET Standard 类库的.NET 平台?
发布评论