Skip to content

Instantly share code, notes, and snippets.

@karenpayneoregon
Created April 4, 2024 13:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenpayneoregon/fe898ab392e9abbb618bef92a8e5c2a3 to your computer and use it in GitHub Desktop.
Save karenpayneoregon/fe898ab392e9abbb618bef92a8e5c2a3 to your computer and use it in GitHub Desktop.
Get DotNet version at runtime
public static Version FrameworkRuntimeVersion()
{
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var path = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
var index = Array.IndexOf(path, "Microsoft.NETCore.App");
return new Version((index > 0 && index < path.Length - 2 ? path[index + 1] : null)!);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment