Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.NET核心当前版本_.net_Asp.net Core_Version - Fatal编程技术网

.NET核心当前版本

.NET核心当前版本,.net,asp.net-core,version,.net,Asp.net Core,Version,如何确定我的应用程序运行在.NET Core的哪个版本 我试图从IHostingEnvironment(也包括Startup.cs和Program.cs)确定这一点,但没有成功 这个问题:与.NET Framework有关。我的问题是关于.NET核心的。您可以从Microsoft.Extensions.PlatformAbstractions下的PlatformServices.Default.Application.RuntimeFramework属性获取运行时版本 在Program.cs中:

如何确定我的应用程序运行在.NET Core的哪个版本

我试图从IHostingEnvironment(也包括Startup.cs和Program.cs)确定这一点,但没有成功


这个问题:与.NET Framework有关。我的问题是关于.NET核心的。

您可以从
Microsoft.Extensions.PlatformAbstractions
下的
PlatformServices.Default.Application.RuntimeFramework
属性获取运行时版本

Program.cs
中:

Console.WriteLine(PlatformServices.Default.Application.RuntimeFramework);
更新: 据此,
Microsoft.Extensions.PlatformAbstractions
已被删除,因此
RuntimeFramework
将替换为:

Console.WriteLine(System.Reflection.Assembly.GetEntryAssembly().GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName);
Console.WriteLine(System.Reflection.Assembly.GetEntryAssembly().GetCustomAttribute().FrameworkName);

快捷方式之一是进入菜单栏,选择
项目->属性->应用程序


然后,您将看到项目使用的目标框架版本是什么。

如果
使用System.Reflection
是不需要的,则可以使用
GetCustomAttributes

static string GetFrameworkName()
            => ((System.Runtime.Versioning.TargetFrameworkAttribute)
                    (System.Reflection.Assembly.GetEntryAssembly()
                    .GetCustomAttributes(typeof(System.Runtime.Versioning.TargetFrameworkAttribute), true)[0]))
                    .FrameworkName; // Example: .NETCoreApp,Version=v3.0