gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:54:47 26 4
gpt4 key购买 nike

.NET Standard Library — One library to rule them all.

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

  • .NET 框架
  • .NET 核心
  • 赛马林

如何查看当前运行 .NET Standard 库的 .NET 平台?

例如:

// 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)?

最佳答案

使用 RuntimeInformation.FrameworkDescription System.Runtime.InteropServices 命名空间中的属性。

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 Framework".

  • ".NET Native".

关于c# - 如何确定运行.NET Standard 类库的.NET 平台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48259320/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com