【问题标题】:.NET Core current version.NET Core 当前版本
【发布时间】:2018-11-11 09:57:39
【问题描述】:
【问题讨论】:
标签:
.net
asp.net-core
version
【解决方案1】:
您可以从Microsoft.Extensions.PlatformAbstractions 下的PlatformServices.Default.Application.RuntimeFramework 属性获取运行时版本。
在Program.cs:
Console.WriteLine(PlatformServices.Default.Application.RuntimeFramework);
更新:
根据这个aspnet/Announcement,Microsoft.Extensions.PlatformAbstractions已经被去掉了,所以RuntimeFramework要替换成:
Console.WriteLine(System.Reflection.Assembly.GetEntryAssembly().GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName);
【解决方案2】:
其中一种快捷方式是转到菜单栏并选择Project->Properties->Application
然后你会看到你的项目使用的目标框架版本是什么。
【解决方案3】:
如果不希望使用using 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