How can I get the current CLR Runtime version in a running .NET program ?
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.
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