如何确定运行.NET Standard 类库的.NET 平台?

编程入门 行业动态 更新时间:2024-10-25 14:23:16
本文介绍了如何确定运行.NET Standard 类库的.NET 平台?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

.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 平台?

本文发布于:2023-11-17 05:48:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609048.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类库   平台   NET   Standard

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!