C# Tip Article
CLR version vs .NET version
CLR version vs .NET version
CLR version and .NET version are different and sometimes little confusing. There are several ways of checking CLR and/or .NET version.
1) Using clrver.exe
Open VS Developer Command Prompt and run clrver.exe. This tool will show CLR versions on the machine.
C:\Program Files (x86)\Microsoft Visual Studio 14.0> clrver Microsoft (R) .NET CLR Version Tool Version 4.6.1055.0 Copyright (c) Microsoft Corporation. All rights reserved. Versions installed on the machine: v2.0.50727 v4.0.30319
2) Using System.Environment.Version in C#
Run the following code in C#. For the result value, the first part 4.0.30319 means CLR version 4.0. And the last part 42000 is the build number which can be interpreted to .NET version number. One caveat is, it is not recommended to use Environment.Version for .NET 4.5 and above (use registry method below).
Console.WriteLine(System.Environment.Version); // Result: 4.0.30319.42000
3) Using Registry
Registry has most accurate .NET version information. Refer to this Microsoft document.
4) Checking clr.dll / mscorwks.dll file version
Similar to #2 method above, one can check clr.dll file version from its [Properties]. That is, for .NET 4 or above, Open [Properties] of C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll file in File Explorer and click [Details] tab and then find [File version]. File version of clr.dll will be formatted as 4.0.30319.(Build#).
For .NET 2.0 ~ 3.5, check file version for C:\Windows\Microsoft.NET\Framework64\v2.0.50727\mscorwks.dll instead. File version will be formatted as 2.0.50727.(Build#).
Here is the summary of CLR 4.0 and .NET 4.x version mapping.
NET Version | Version |
.NET 4.0 | 4.0.30319.0 to 4.0.30319.17000 |
.NET 4.5 | 4.0.30319.17001 to 4.0.3019.18400 |
.NET 4.5.1 | 4.0.30319.18401 to 4.0.30319.34000 |
.NET 4.5.2 | 4.0.30319.34001 to 4.0.30319.41999 |
.NET 4.6+ | From 4.0.30319.42000 |
5) Check CLR version From SQL Server
CLR version can be found by executing the following query. This might be useful when checking CLR version for SQLCLR programming.
SELECT * FROM sys.dm_clr_properties where name='version'