Procedura: Determinare le versioni di .NET Framework installate

Nota

Questo articolo è specifico per .NET Framework. Per determinare quali SDK e runtime .NET Core e .NET 5+ sono installati, vedere Come verificare che .NET sia già installato.

È possibile installare ed eseguire più versioni di .NET Framework in un computer.

  • Se si vogliono controllare le versioni nel proprio computer, il modo più semplice è tramite Pannello di controllo>Programmi>Programmi e funzionalità o in Impostazioni in App>App installate. È anche possibile usare questi strumenti gestiti dalla community.
  • Per gli sviluppatori di app può essere necessario conoscere quali versioni di .NET Framework sono installate nel computer dell'utente dell'app. Il Registro di sistema contiene un elenco delle versioni di .NET Framework installate nel computer. È anche possibile eseguire una query sulla proprietà RuntimeInformation.FrameworkDescription.
  • Per trovare la versione di CLR, la cui versione è definita separatamente, vedere Trovare le versioni di CLR.

.NET Framework è costituito da due componenti principali, le cui versioni sono definite separatamente:

  • Un set di assembly, ovvero raccolte di tipi e risorse che forniscono la funzionalità per le app. .NET Framework e gli assembly condividono il numero di versione. Ad esempio, le versioni di .NET Framework includono 4.5, 4.6.1 e 4.7.2.
  • Common Language Runtime (CLR), che gestisce ed esegue il codice dell'app In genere una singola versione di CLR supporta più versioni di .NET Framework. Ad esempio, CLR versione 4.0.30319.xxxxx, dove xxxxx è minore di 42000, supporta le versioni di .NET Framework da 4 a 4.5.2. La versione CLR successiva o uguale a 4.0.30319.42000 supporta le versioni di .NET Framework a partire da .NET Framework 4.6.

Suggerimento

Per informazioni sul rilevamento degli aggiornamenti installati per ogni versione di .NET Framework, vedere Procedura: Determinare gli aggiornamenti di .NET Framework installati.

Strumenti gestiti dalla community

Per rilevare le versioni di .NET Framework installate sono disponibili alcuni strumenti gestiti dalla community:

Proprietà RuntimeInformation.FrameworkDescription

È possibile usare la proprietà RuntimeInformation.FrameworkDescription per eseguire una query a livello di codice sulla versione di .NET in cui è in esecuzione l'app. Se l'app è in esecuzione in .NET Framework, l'output sarà simile al seguente:

.NET Framework 4.8.4250.0

Per confronto, se l'app è in esecuzione in .NET Core o .NET 5+, l'output sarà simile al seguente:

.NET Core 3.1.9
.NET 5.0.0

Registro

È possibile usare il Registro di sistema per rilevare la versione di .NET Framework installata. Le chiavi sono diverse per .NET Framework 1.0-4.0 e .NET Framework 4.5+. È possibile usare l'Editor del Registro di sistema, PowerShell o il codice per controllare il Registro di sistema.

.NET Framework 4.5 e versioni successive

La versione di .NET Framework (4.5 e successive) installata in un computer è elencata nel registro in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. Se la sottochiave Full manca, .NET Framework 4.5 o versione successiva non è installato.

Nota

La sottochiave NET Framework Setup nel percorso del registro non inizia con un punto.

Il valore Release REG_DWORD nel registro rappresenta la versione di .NET Framework installata.

Versione di .NET Framework Valore di Release
.NET Framework 4.5 Tutti i sistemi operativi Windows: 378389
.NET Framework 4.5.1 In Windows 8.1 e Windows Server 2012 R2: 378675
In tutti gli altri sistemi operativi Windows: 378758
.NET Framework 4.5.2 Tutti i sistemi operativi Windows: 379893
.NET Framework 4.6 In Windows 10: 393295
In tutti gli altri sistemi operativi Windows: 393297
.NET Framework 4.6.1 Nei sistemi Windows 10 aggiornamento di novembre: 394254
In tutti gli altri sistemi operativi Windows (incluso Windows 10): 394271
.NET Framework 4.6.2 Nell'Aggiornamento dell'anniversario di Windows 10 e in Windows Server 2016: 394802
In tutti gli altri sistemi operativi Windows (inclusi altri sistemi operativi Windows 10): 394806
.NET Framework 4.7 In Windows 10 Creators Update: 460798
In tutti gli altri sistemi operativi Windows (inclusi altri sistemi operativi Windows 10): 460805
.NET Framework 4.7.1 In Windows 10 Fall Creators Update e Windows Server versione 1709: 461308
In tutti gli altri sistemi operativi Windows (inclusi altri sistemi operativi Windows 10): 461310
.NET Framework 4.7.2 In Windows 10 aggiornamento di aprile 2018 e Windows Server versione 1803: 461808
In tutti i sistemi operativi diversi dall'Aggiornamento di Windows 10 (aprile 2018) e da Windows Server, versione 1803: 461814
.NET Framework 4.8 In Windows 10 aggiornamento di maggio 2019 e Windows 10 aggiornamento di novembre 2019: 528040
In Windows 10 aggiornamento di maggio 2020, aggiornamento di ottobre 2020, aggiornamento di maggio 2021, aggiornamento di novembre 2021 e aggiornamento del 2022: 528372
In Windows 11 e Windows Server 2022: 528449
In tutti gli altri sistemi operativi Windows (inclusi altri sistemi operativi Windows 10): 528049
.NET Framework 4.8.1 In Windows 11 aggiornamento del 2022 e Windows 11 aggiornamento del 2023: 533320
In tutti gli altri sistemi operativi Windows: 533325

Versione minima

Per determinare se è presente una versione minima di .NET Framework, verificare se è presente un valore Release REG_DWORD maggiore o uguale al valore corrispondente elencato nella tabella seguente. Se ad esempio l'applicazione viene eseguita in .NET Framework 4.8 o versione successiva, verificare se è presente un valore Release REG_DWORD maggiore o uguale a 528040.

Versione di .NET Framework Valore minimo
.NET Framework 4.5 378389
.NET Framework 4.5.1 378675
.NET Framework 4.5.2 379893
.NET Framework 4.6 393295
.NET Framework 4.6.1 394254
.NET Framework 4.6.2 394802
.NET Framework 4.7 460798
.NET Framework 4.7.1 461308
.NET Framework 4.7.2 461808
.NET Framework 4.8 528040
.NET Framework 4.8.1 533320

Usare l'Editor del Registro di sistema

  1. Dal menu Start scegliere Esegui, immettere regedit e quindi selezionare OK.

    Per eseguire regedit, è necessario avere le credenziali amministrative.

  2. Nell'editor del registro aprire la sottochiave seguente: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. Se la sottochiave Full non è presente, .NET Framework 4.5 o versioni successive non è installato.

  3. Verificare la presenza di una voce REG_DWORD denominata Release. Se esiste, .NET Framework 4.5 o versioni successive è installato. Il valore corrisponde a una determinata versione di .NET Framework. Nella figura seguente, ad esempio, il valore della voce Release è 528040, ovvero la chiave di rilascio per .NET Framework 4.8.

    Voce del Registro di sistema per .NET Framework 4.5

Usare PowerShell per verificare la versione minima

Usare i comandi PowerShell per verificare il valore della voce Release della sottochiave HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full.

Gli esempi seguenti illustrano come verificare il valore della voce Release per determinare se .NET Framework 4.6.2 o versioni successive è installato. Questo codice restituisce True se è installato e False in caso contrario.

(Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release) -ge 394802

Eseguire query nel Registro di sistema usando il codice

  1. Usare i metodi RegistryKey.OpenBaseKey e RegistryKey.OpenSubKey per accedere alla sottochiave HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full nel Registro di sistema di Windows.

    Importante

    Se l'app in esecuzione è a 32 bit ed è in esecuzione in Windows a 64 bit, i percorsi del registro saranno diversi da quelli elencati in precedenza. Il registro a 64 bit è disponibile nella sottochiave HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\. Ad esempio, la sottochiave del registro per .NET Framework 4.5 è HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v4\Full.

  2. Verificare il valore di Release REG_DWORD per determinare la versione installata. Affinché sia compatibile con la versione attualmente installata, è possibile cercare un valore maggiore o uguale ai valori elencati nella tabella delle versioni di .NET Framework.

L'esempio seguente illustra come verificare il valore della voce Release nel registro per determinare quali versioni di .NET Framework 4.5-4.8.1 sono installate.

Suggerimento

Aggiungere la direttiva using Microsoft.Win32 o Imports Microsoft.Win32 all'inizio del file di codice, se non è già stato fatto.

const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";

using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
{
    if (ndpKey != null && ndpKey.GetValue("Release") != null)
    {
        Console.WriteLine($".NET Framework Version: {CheckFor45PlusVersion((int)ndpKey.GetValue("Release"))}");
    }
    else
    {
        Console.WriteLine(".NET Framework Version 4.5 or later is not detected.");
    }
}

// Checking the version using >= enables forward compatibility.
string CheckFor45PlusVersion(int releaseKey)
{
    if (releaseKey >= 533320)
        return "4.8.1 or later";
    if (releaseKey >= 528040)
        return "4.8";
    if (releaseKey >= 461808)
        return "4.7.2";
    if (releaseKey >= 461308)
        return "4.7.1";
    if (releaseKey >= 460798)
        return "4.7";
    if (releaseKey >= 394802)
        return "4.6.2";
    if (releaseKey >= 394254)
        return "4.6.1";
    if (releaseKey >= 393295)
        return "4.6";
    if (releaseKey >= 379893)
        return "4.5.2";
    if (releaseKey >= 378675)
        return "4.5.1";
    if (releaseKey >= 378389)
        return "4.5";
    // This code should never execute. A non-null release key should mean
    // that 4.5 or later is installed.
    return "No 4.5 or later version detected";
}
Private Sub Get45PlusFromRegistry()
    Const subkey As String = "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"

    Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)
        If ndpKey IsNot Nothing AndAlso ndpKey.GetValue("Release") IsNot Nothing Then
            Console.WriteLine($".NET Framework Version: {CheckFor45PlusVersion(ndpKey.GetValue("Release"))}")
        Else
            Console.WriteLine(".NET Framework Version 4.5 or later is not detected.")
        End If
    End Using
End Sub

' Checking the version using >= enables forward compatibility.
Private Function CheckFor45PlusVersion(releaseKey As Integer) As String
    If releaseKey >= 533320 Then
        Return "4.8.1 or later"
    ElseIf releaseKey >= 528040 Then
        Return "4.8"
    ElseIf releaseKey >= 461808 Then
        Return "4.7.2"
    ElseIf releaseKey >= 461308 Then
        Return "4.7.1"
    ElseIf releaseKey >= 460798 Then
        Return "4.7"
    ElseIf releaseKey >= 394802 Then
        Return "4.6.2"
    ElseIf releaseKey >= 394254 Then
        Return "4.6.1"
    ElseIf releaseKey >= 393295 Then
        Return "4.6"
    ElseIf releaseKey >= 379893 Then
        Return "4.5.2"
    ElseIf releaseKey >= 378675 Then
        Return "4.5.1"
    ElseIf releaseKey >= 378389 Then
        Return "4.5"
    End If
    ' This code should never execute. A non-null release key should mean
    ' that 4.5 or later is installed.
    Return "No 4.5 or later version detected"
End Function

Nell'esempio viene visualizzato un output come il seguente:

.NET Framework Version: 4.6.1

Eseguire query nel Registro di sistema usando PowerShell

L'esempio seguente illustra come usare PowerShell per verificare il valore della voce Release nel registro per determinare quali versioni di .NET Framework 4.5-4.8.1 sono installate:

$release = Get-ItemPropertyValue -LiteralPath 'HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full' -Name Release
switch ($release) {
    { $_ -ge 533320 } { $version = '4.8.1 or later'; break }
    { $_ -ge 528040 } { $version = '4.8'; break }
    { $_ -ge 461808 } { $version = '4.7.2'; break }
    { $_ -ge 461308 } { $version = '4.7.1'; break }
    { $_ -ge 460798 } { $version = '4.7'; break }
    { $_ -ge 394802 } { $version = '4.6.2'; break }
    { $_ -ge 394254 } { $version = '4.6.1'; break }
    { $_ -ge 393295 } { $version = '4.6'; break }
    { $_ -ge 379893 } { $version = '4.5.2'; break }
    { $_ -ge 378675 } { $version = '4.5.1'; break }
    { $_ -ge 378389 } { $version = '4.5'; break }
    default { $version = $null; break }
}

if ($version) {
    Write-Host -Object ".NET Framework Version: $version"
} else {
    Write-Host -Object '.NET Framework Version 4.5 or later is not detected.'
}

Questo esempio segue la procedura consigliata per il controllo della versione:

  • Verifica se il valore della voce Release è maggiore o uguale al valore delle parole chiave Release note.
  • Controlla in ordine dalla versione più recente a quella meno recente.

.NET Framework 1.0-4.0

Ogni versione di .NET Framework da 1.1 a 4.0 è elencata come sottochiave in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP. La tabella seguente elenca il percorso di ogni versione di .NET Framework. Per la maggior parte delle versioni, è presente un valore Install REG_DWORD per 1 a indicare che questa versione è installata. In queste sottochiavi è presente anche un valore Version REG_SZ che contiene una stringa di versione.

Nota

La sottochiave NET Framework Setup nel percorso del registro non inizia con un punto.

Versione framework Sottochiave del registro Valore
1.0 HKLM\Software\Microsoft\.NETFramework\Policy\v1.0\3705 Install REG_SZ è uguale a 1
1.1 HKLM\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322 Install REG_DWORD è uguale a 1
2.0 HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727 Install REG_DWORD è uguale a 1
3,0 HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup InstallSuccess REG_DWORD è uguale a 1
3.5 HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.5 Install REG_DWORD è uguale a 1
Profilo client 4.0 HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Client Install REG_DWORD è uguale a 1
Profilo completo 4.0 HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full Install REG_DWORD è uguale a 1

Importante

Se l'app in esecuzione è a 32 bit ed è in esecuzione in Windows a 64 bit, i percorsi del registro saranno diversi da quelli elencati in precedenza. Il registro a 64 bit è disponibile nella sottochiave HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\. Ad esempio, la sottochiave del registro per .NET Framework 3.5 è HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v3.5.

Si noti che il percorso del registro per la sottochiave .NET Framework 1.0 è diverso dagli altri.

Usare l'editor del registro (versioni precedenti del framework)

  1. Dal menu Start scegliere Esegui, immettere regedit e quindi selezionare OK.

    Per eseguire regedit, è necessario avere le credenziali amministrative.

  2. Aprire la sottochiave corrispondente alla versione da controllare. Usare la tabella nella sezione .NET Framework 1.0-4.0.

    La figura seguente illustra la sottochiave e il relativo valore Version per .NET Framework 3.5.

    Voce del Registro di sistema per .NET Framework 3.5.

Eseguire query nel registro usando il codice (versioni precedenti del framework)

Usare la classe Microsoft.Win32.RegistryKey per accedere alla sottochiave HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP nel registro di Windows.

Importante

Se l'app in esecuzione è a 32 bit ed è in esecuzione in Windows a 64 bit, i percorsi del registro saranno diversi da quelli elencati in precedenza. Il registro a 64 bit è disponibile nella sottochiave HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\. Ad esempio, la sottochiave del registro per .NET Framework 3.5 è HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v3.5.

L'esempio seguente illustra come trovare le versioni .NET Framework da 1 a 4 installate:

// Open the registry key for the .NET Framework entry.
using (RegistryKey ndpKey =
        RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).
        OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
{
    foreach (var versionKeyName in ndpKey.GetSubKeyNames())
    {
        // Skip .NET Framework 4.5 version information.
        if (versionKeyName == "v4")
        {
            continue;
        }

        if (versionKeyName.StartsWith("v"))
        {
            RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);

            // Get the .NET Framework version value.
            var name = (string)versionKey.GetValue("Version", "");
            // Get the service pack (SP) number.
            var sp = versionKey.GetValue("SP", "").ToString();

            // Get the installation flag.
            var install = versionKey.GetValue("Install", "").ToString();
            if (string.IsNullOrEmpty(install))
            {
                // No install info; it must be in a child subkey.
                Console.WriteLine($"{versionKeyName}  {name}");
            }
            else if (install == "1")
            {
                // Install = 1 means the version is installed.

                if (!string.IsNullOrEmpty(sp))
                {
                    Console.WriteLine($"{versionKeyName}  {name}  SP{sp}");
                }
                else
                {
                    Console.WriteLine($"{versionKeyName}  {name}");
                }
            }

            if (!string.IsNullOrEmpty(name))
            {
                continue;
            }
            // else print out info from subkeys...

            // Iterate through the subkeys of the version subkey.
            foreach (var subKeyName in versionKey.GetSubKeyNames())
            {
                RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
                name = (string)subKey.GetValue("Version", "");
                if (!string.IsNullOrEmpty(name))
                    sp = subKey.GetValue("SP", "").ToString();

                install = subKey.GetValue("Install", "").ToString();
                if (string.IsNullOrEmpty(install))
                {
                    // No install info; it must be later.
                    Console.WriteLine($"  {versionKeyName}  {name}");
                }
                else if (install == "1")
                {
                    if (!string.IsNullOrEmpty(sp))
                    {
                        Console.WriteLine($"  {subKeyName}  {name}  SP{sp}");
                    }
                    else
                    {
                        Console.WriteLine($"  {subKeyName}  {name}");
                    }
                }
            }
        }
    }
}
' Opens the registry key for the .NET Framework entry.
Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).
    OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\")

    For Each versionKeyName In ndpKey.GetSubKeyNames()
        ' Skip .NET Framework 4.5 and later.
        If versionKeyName = "v4" Then Continue For

        If versionKeyName.StartsWith("v") Then
            Dim versionKey As RegistryKey = ndpKey.OpenSubKey(versionKeyName)
            ' Get the .NET Framework version value.
            Dim name = DirectCast(versionKey.GetValue("Version", ""), String)
            ' Get the service pack (SP) number.
            Dim sp = versionKey.GetValue("SP", "").ToString()

            Dim install = versionKey.GetValue("Install", "").ToString()
            If String.IsNullOrEmpty(install) Then
                ' No install info; it must be in a child subkey.
                Console.WriteLine($"{versionKeyName}  {name}")
            ElseIf install = "1" Then

                If Not String.IsNullOrEmpty(sp) Then
                    Console.WriteLine($"{versionKeyName}  {name}  SP{sp}")
                Else
                    Console.WriteLine($"{versionKeyName}  {name}")
                End If

            End If

            If Not String.IsNullOrEmpty(name) Then
                Continue For
            End If

            For Each subKeyName In versionKey.GetSubKeyNames()
                Dim subKey As RegistryKey = versionKey.OpenSubKey(subKeyName)
                name = DirectCast(subKey.GetValue("Version", ""), String)
                If Not String.IsNullOrEmpty(name) Then
                    sp = subKey.GetValue("SP", "").ToString()
                End If

                install = subKey.GetValue("Install", "").ToString()
                If String.IsNullOrEmpty(install) Then
                    ' No install info; it must be later.
                    Console.WriteLine($"  {versionKeyName}  {name}")
                ElseIf install = "1" Then

                    If Not String.IsNullOrEmpty(sp) Then
                        Console.WriteLine($"  {subKeyName}  {name}  SP{sp}")
                    Else
                        Console.WriteLine($"  {subKeyName}  {name}")
                    End If

                End If
            Next
        End If
    Next
End Using

Verrà visualizzato un output simile a quello riportato di seguito:

v2.0.50727  2.0.50727.4927  SP2
v3.0  3.0.30729.4926  SP2
v3.5  3.5.30729.4926  SP1
v4.0
  Client  4.0.0.0

Eseguire query nel registro usando PowerShell (versioni precedenti del framework)

L'esempio seguente illustra come usare PowerShell per verificare il valore della voce Release nel registro per determinare quali versioni di .NET Framework 1-4 sono installate:

Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' |
Where-Object { ($_.PSChildName -ne "v4") -and ($_.PSChildName -like 'v*') } |
ForEach-Object {
    $name = $_.Version
    $sp = $_.SP
    $install = $_.Install
    if (-not $install) {
        Write-Host -Object "$($_.PSChildName)  $($name)"
    }
    elseif ($install -eq '1') {
        if (-not $sp) {
            Write-Host -Object "$($_.PSChildName)  $($name)"
        }
        else {
            Write-Host -Object "$($_.PSChildName)  $($name) SP$($sp)"
        }
}
    if (-not $name) {
        $parentName = $_.PSChildName
        Get-ChildItem -LiteralPath $_.PSPath |
        Where-Object {
            if ($_.Property -contains 'Version') { $name = Get-ItemPropertyValue -Path $_.PSPath -Name Version }
            if ($name -and ($_.Property -contains 'SP')) { $sp = Get-ItemPropertyValue -Path $_.PSPath -Name SP }
            if ($_.Property -contains 'Install') { $install = Get-ItemPropertyValue -Path $_.PSPath -Name Install }
            if (-not $install) {
                Write-Host -Object "  $($parentName)  $($name)"
            }
            elseif ($install -eq '1') {
                if (-not $sp) {
                    Write-Host -Object "  $($_.PSChildName)  $($name)"
                }
                else {
                    Write-Host -Object "  $($_.PSChildName)  $($name) SP$($sp)"
                }
            }
        }
    }
}

Trovare le versioni di CLR

Le versioni di CLR .NET Framework installato con .NET Framework sono definite separatamente. Esistono due modi per rilevare la versione di CLR .NET Framework:

Strumento Clrver.exe

Usare lo strumento della versione CLR (Clrver.exe) per determinare le versioni di CLR installate in un computer. Aprire il prompt dei comandi per gli sviluppatori di Visual Studio o Visual Studio Developer PowerShell e immettere clrver.

Output di esempio:

Versions installed on the machine:
v2.0.50727
v4.0.30319

La proprietà Environment.Version

Importante

Per .NET Framework 4.5 e versioni successive, non usare la proprietà Environment.Version per rilevare la versione di CLR. Eseguire invece una query nel Registro di sistema come descritto in .NET Framework 4.5 e versioni successive.

  1. Eseguire la query per la proprietà Environment.Version per recuperare un oggetto Version.

    L'oggetto System.Version identifica la versione del runtime che esegue attualmente il codice. Non restituisce le versioni di assembly o altre versioni del runtime che potrebbero essere state installate nel computer.

    Per le versioni 4, 4.5, 4.5.1 e 4.5.2 di .NET Framework, la rappresentazione stringa dell'oggetto Version restituito ha il formato 4.0.30319.xxxxx, dove xxxxx è inferiore a 42000. Per .NET Framework 4.6 e versioni successive, ha il formato 4.0.30319.42000.

  2. Dopo aver ottenuto l'oggetto Version, eseguire una query come indicato di seguito:

    • Per l'identificatore della versione principale (ad esempio, 4 per la versione 4.0), usare la proprietà Version.Major.
    • Per l'identificatore della versione secondaria (ad esempio, 0 per la versione 4.0), usare la proprietà Version.Minor.
    • Per l'intera stringa di versione (ad esempio, 4.0.30319.18010), usare il metodo Version.ToString. Questo metodo restituisce un valore singolo che riflette la versione del runtime che esegue il codice. Non restituisce le versioni di assembly o altre versioni del runtime che potrebbero essere installate nel computer.

L'esempio seguente usa la proprietà Environment.Version per recuperare le informazioni sulla versione di CLR:

Console.WriteLine($"Version: {Environment.Version}");
Console.WriteLine($"Version: {Environment.Version}")

Verrà visualizzato un output simile a quello riportato di seguito:

Version: 4.0.30319.18010

Vedi anche