2

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.

Uros
  • 2,099
  • 7
  • 23
  • 50

3 Answers3

2

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);
junkangli
  • 1,152
  • 7
  • 14
0

One of the quick ways is going to the menu bar and choose Project->Properties->Application

enter image description here

Then you'll see what's the target framework version your project is using.

mark333...333...333
  • 1,270
  • 1
  • 11
  • 26
0

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
tymtam
  • 31,798
  • 8
  • 86
  • 126