.NET核心当前版本
如何确定我的应用程序运行在.NET Core的哪个版本 我试图从IHostingEnvironment(也包括Startup.cs和Program.cs)确定这一点,但没有成功.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 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