Get Current .NET CLR version at runtime?

爱⌒轻易说出口 提交于 2019-11-29 09:03:01
Laurent Etiemble

Check out System.Environment.Version property (http://msdn.microsoft.com/en-us/library/system.environment.version.aspx).

Since .NET 4.5 you can't really use System.Environment.Version (it will only return 4.0.{something}, allowing you to verify that you're "at least" on 4.0 but not telling you which actual version is available unless you can map a full list of build numbers in).

Instead (as @jim-w mentioned) you have to check the registry against a "simple" lookup table. It's a bit ridiculous and being Windows-specific, does not work for .NET Core ...

However ... starting in .NET 4.7.1, they've back-ported a class from .NET Core into the full framework, and you can now check System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription

Unfortunately, it returns a string with either: ".NET Core", ".NET Framework", or ".NET Native" before the version number -- so you still have some parsing to do.

David Kemp

Try Environment.Version to get that info. Also you may need to call ToString().

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!