Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Annotazioni
Questo articolo è specifico di .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 vuoi controllare le versioni nel tuo computer, il modo più semplice consiste nell'usareProgrammi>e funzionalità del > di controllo o in Impostazioni in App>installate. È anche possibile usare questi strumenti gestiti dalla community.
- Se si è uno sviluppatore di app, potrebbe essere necessario conoscere le versioni di .NET Framework 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
RuntimeInformation.FrameworkDescriptionproprietà . - Per trovare la versione CLR, che ha una versione separata, vedere Trovare versioni CLR.
.NET Framework è costituito da due componenti principali, che vengono con versione separata:
- Un insieme di assembly, che sono raccolte di tipi e risorse che forniscono funzionalità per le tue app. .NET Framework e gli assembly condividono lo stesso 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. Una singola versione CLR supporta in genere più versioni di .NET Framework. Ad esempio, CLR versione 4.0.30319. xxxxx dove xxxxx è minore di 42000, supporta .NET Framework versioni 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
Gli strumenti gestiti dalla community sono disponibili per rilevare le versioni di .NET Framework installate:
RuntimeInformation.FrameworkDescription proprietà
Per eseguire una query a livello di codice per la versione .NET in cui è in esecuzione l'app, è possibile usare la RuntimeInformation.FrameworkDescription proprietà . 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
Registry
È 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 versioni successive) installata in un computer è elencata nel Registro di sistema in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. Se manca la sottochiave Completa , .NET Framework 4.5 o versione successiva non è installato.
Annotazioni
La sottochiave di installazione di NET Framework nel percorso del Registro di sistema non inizia con un punto.
Il valore Release REG_DWORD nel Registro di sistema rappresenta la versione di .NET Framework installata.
| Versione di .NET Framework | Valore del rilascio |
|---|---|
| .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 di aggiornamento di novembre di Windows 10: 394254 In tutti gli altri sistemi operativi Windows (incluso Windows 10): 394271 |
| .NET Framework 4.6.2 | In Windows 10 Anniversary Update e 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 April 2018 Update e Windows Server versione 1803: 461808 In tutti i sistemi operativi Windows diversi da Windows 10 April 2018 Update e 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 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 2025 Update: 533509 In Windows 11 2022 Update e Windows 11 2023 Update: 533320 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. Ad esempio, se l'applicazione viene eseguita in .NET Framework 4.8 o versione successiva, eseguire il test per 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
Dal menu Start scegliere Esegui, immettere regedit e quindi selezionare OK.
Per eseguire regedit, è necessario disporre delle credenziali amministrative.
Nell'editor del Registro di sistema aprire la sottochiave seguente: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full. Se la sottochiave Full non è presente, non è installato .NET Framework 4.5 o versione successiva.
Verificare la presenza di una voce REG_DWORD denominata Release. Se esiste, è installato .NET Framework 4.5 o versione successiva. Il valore corrisponde a una versione specifica di .NET Framework. Nella figura seguente, ad esempio, il valore della voce Release è 528040, ovvero la chiave di rilascio per .NET Framework 4.8.
Usare PowerShell per verificare la disponibilità di una versione minima
Usare i comandi di PowerShell per controllare il valore della voce Release della sottochiaveHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full .
Gli esempi seguenti controllano il valore della voce Release per determinare se è installato .NET Framework 4.6.2 o versione successiva. 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
Utilizzare i RegistryKey.OpenBaseKey metodi 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 di sistema saranno diversi da quelli elencati in precedenza. Il Registro di sistema a 32 bit è disponibile nella sottochiave HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ . Ad esempio, la sottochiave del Registro di sistema per .NET Framework 4.5 è HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v4\Full.
Controllare il valore Release REG_DWORD per determinare la versione installata. Per essere compatibile con le versioni future, verificare la presenza di un valore maggiore o uguale al valore elencato nella tabella delle versioni di .NET Framework.
Nell'esempio seguente viene controllato il valore della voce Release nel Registro di sistema per trovare le versioni di .NET Framework 4.5-4.8.1 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 (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32))
using (RegistryKey ndpKey = baseKey.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 baseKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32),
ndpKey As RegistryKey = baseKey.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
Select Case releaseKey
Case >= 533320 : Return "4.8.1 or later"
Case >= 528040 : Return "4.8"
Case >= 461808 : Return "4.7.2"
Case >= 461308 : Return "4.7.1"
Case >= 460798 : Return "4.7"
Case >= 394802 : Return "4.6.2"
Case >= 394254 : Return "4.6.1"
Case >= 393295 : Return "4.6"
Case >= 379893 : Return "4.5.2"
Case >= 378675 : Return "4.5.1"
Case >= 378389 : Return "4.5"
Case Else
Return "No 4.5 or later version detected"
End Select
End Function
Nell'esempio viene visualizzato un output simile al seguente:
.NET Framework Version: 4.6.1
Eseguire query nel Registro di sistema usando PowerShell
L'esempio seguente usa PowerShell per controllare il valore della voce Release nel Registro di sistema per trovare le versioni di .NET Framework 4.5-4.8.1 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 dei valori di versione noti.
- Controlla in ordine dalla versione più recente alla versione 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 indicare che questa versione è installata. In queste sottochiavi è presente anche un valore version REG_SZ che contiene una stringa di versione.
Annotazioni
La sottochiave di installazione di NET Framework nel percorso del Registro di sistema non inizia con un punto.
| Versione del framework | Sottochiave del Registro di sistema | Value |
|---|---|---|
| 1.0 | HKLM\Software\Microsoft\. NETFramework\Policy\v1.0\3705 |
Installare REG_SZ equivale a 1 |
| 1.1 | HKLM\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322 |
Installa REG_DWORD = 1 |
| 2.0 | HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727 |
Installare REG_DWORD equivale 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 |
Installa REG_DWORD corrisponde a 1 |
| 4.0 Profilo cliente | HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Client |
Install REG_DWORD è uguale a 1 |
| 4.0 Profilo completo | HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full |
Installare 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 di sistema saranno diversi da quelli elencati in precedenza. Il Registro di sistema a 32 bit è disponibile nella sottochiave HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ . Ad esempio, la sottochiave del Registro di sistema per .NET Framework 3.5 è HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v3.5.
Si noti che il percorso del Registro di sistema per la sottochiave .NET Framework 1.0 è diverso dagli altri.
Usare l'editor del Registro di sistema (versioni precedenti del framework)
Dal menu Start scegliere Esegui, immettere regedit e quindi selezionare OK.
Per eseguire regedit, è necessario disporre di credenziali amministrative.
Aprire la sottochiave corrispondente alla versione da controllare. Usare la tabella nella sezione .NET Framework 1.0-4.0 .
La figura seguente mostra la sottochiave e il relativo valore Version per .NET Framework 3.5.
Eseguire query nel Registro di sistema usando il codice (versioni precedenti del framework)
Usare la Microsoft.Win32.RegistryKey classe per accedere alla sottochiaveHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP 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 di sistema saranno diversi da quelli elencati in precedenza. Il Registro di sistema a 32 bit è disponibile nella sottochiave HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ . Ad esempio, la sottochiave del Registro di sistema per .NET Framework 3.5 è HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v3.5.
L'esempio seguente trova le versioni installate di .NET Framework dalla 1 alla 4:
// Open the registry key for the .NET Framework entry. Dispose this object when done.
RegistryKey ndpKey =
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\");
foreach (string 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.
string name = versionKey.GetValue("Version", "").ToString();
// Get the service pack (SP) number.
string sp = versionKey.GetValue("SP", "").ToString();
// Get the installation flag.
string 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))
{
versionKey.Dispose();
continue;
}
// Iterate through the subkeys of the version subkey.
foreach (string subKeyName in versionKey.GetSubKeyNames())
{
RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
name = subKey.GetValue("Version", "").ToString();
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}");
}
// Clean up the subkey object.
subKey.Dispose();
}
versionKey.Dispose();
}
}
ndpKey.Dispose();
' Open the registry key for the .NET Framework entry. Dispose this object when done.
Dim 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 = versionKey.GetValue("Version", "").ToString()
' 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
' Install = 1 means the version is installed.
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
versionKey.Dispose()
Continue For
End If
' Iterate through the subkeys of the version subkey.
For Each subKeyName In versionKey.GetSubKeyNames()
Dim subKey As RegistryKey = versionKey.OpenSubKey(subKeyName)
name = subKey.GetValue("Version", "").ToString()
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
' Clean up the subkey object.
subKey.Dispose()
Next
versionKey.Dispose()
End If
Next
ndpKey.Dispose()
Nell'esempio viene visualizzato un output simile al seguente:
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 di sistema usando PowerShell (versioni precedenti del framework)
L'esempio seguente usa PowerShell per controllare il valore della voce Release nel Registro di sistema per trovare le versioni di .NET Framework 1-4 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-ItemProperty -Path "Registry::$_").Version) }
if ($name -and ($_.Property -contains 'SP')) { $sp = $((Get-ItemProperty -Path "Registry::$_").SP) }
if ($_.Property -contains 'Install') { $install = $((Get-ItemProperty -Path "Registry::$_").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 CLR
La CLR del .NET Framework installata con .NET Framework ha una versione separata. Esistono due modi per rilevare la versione di .NET Framework CLR:
Lo strumento Clrver.exe
Usare lo strumento 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
Proprietà Environment.Version
Importante
Per .NET Framework 4.5 e versioni successive, non usare la Environment.Version proprietà per rilevare la versione di CLR. Eseguire invece una query sul Registro di sistema come descritto in .NET Framework 4.5 e versioni successive.
Eseguire una query sulla Environment.Version proprietà per recuperare un Version oggetto .
L'oggetto restituito
System.Versionidentifica la versione del runtime che esegue attualmente il codice. Non restituisce versioni dell'assembly o altre versioni del runtime che potrebbero essere state installate nel computer.Per .NET Framework versioni 4, 4.5, 4.5.1 e 4.5.2, la rappresentazione di stringa dell'oggetto restituito Version ha il formato 4.0.30319.xxxxx, dove xxxxx è minore di 42000. Per .NET Framework 4.6 e versioni successive, ha il formato 4.0.30319.42000.
Dopo aver ottenuto l'oggetto Version , eseguirne una query nel modo seguente:
- Per l'identificatore di versione principale (ad esempio, 4 per la versione 4.0), usare la Version.Major proprietà .
- Per l'identificatore di 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 Version.ToString metodo . Questo metodo restituisce un singolo valore che riflette la versione del runtime che esegue il codice. Non restituisce versioni di assembly o altre versioni di runtime che possono essere installate nel computer.
Nell'esempio seguente viene utilizzata la Environment.Version proprietà per recuperare le informazioni sulla versione clr:
Console.WriteLine($"Version: {Environment.Version}");
Console.WriteLine($"Version: {Environment.Version}")
Nell'esempio viene visualizzato un output simile al seguente:
Version: 4.0.30319.18010