Reputation: 2150
How can I determine in which version of .NET Core is my app running?
I tried to determine this from IHostingEnvironment (also Startup.cs and Program.cs) without success.
This question: Get Current .NET CLR version at runtime? is related to .NET Framework. My question is about .NET Core.
Upvotes: 2
Views: 241
Reputation: 35135
If using System.Reflection;
is undesired, then GetCustomAttributes
can be used.
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
Upvotes: 0
Reputation: 1360
One of the quick ways is going to the menu bar and choose Project->Properties->Application
Then you'll see what's the target framework version your project is using.
Upvotes: 0
Reputation: 1212
You can get the runtime version from PlatformServices.Default.Application.RuntimeFramework
property under Microsoft.Extensions.PlatformAbstractions
.
In Program.cs
:
Console.WriteLine(PlatformServices.Default.Application.RuntimeFramework);
UPDATED:
According to this aspnet/Announcement, Microsoft.Extensions.PlatformAbstractions
has been removed, so RuntimeFramework
is to be replaced with:
Console.WriteLine(System.Reflection.Assembly.GetEntryAssembly().GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName);
Upvotes: 2