如何确定运行.NET Standard类库的.NET平台? [英] How to determine the .NET platform that runs the .NET Standard class library?

查看:214
本文介绍了如何确定运行.NET Standard类库的.NET平台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET标准库—一个库

.NET标准库功能可能因运行它的.NET平台而异:

The .NET Standard Library functionality may vary depending on the .NET platform that runs it:


  • .NET Framework

  • .NET Core

  • Xamarin

如何检查.NET标准库当前运行的.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.


返回一个字符串,该字符串指示

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 Framework。

".NET Framework".

。NET Native。

".NET Native".

这篇关于如何确定运行.NET Standard类库的.NET平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆