Get Current .NET CLR version at runtime?

早过忘川 提交于 2019-11-28 02:24:12

问题


How can I get the current CLR Runtime version in a running .NET program ?


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/1826688/get-current-net-clr-version-at-runtime

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