.Net: How do I find the .NET version?

后端 未结 19 2453
我寻月下人不归
我寻月下人不归 2020-11-28 00:49

How do I find out which version of .NET is installed?

I\'m looking for something as simple as \"java -version\" that I can type at the command prompt and that tells

19条回答
  •  独厮守ぢ
    2020-11-28 01:09

    Here is the Power Shell script which I used by taking the reference of:

    https://stackoverflow.com/a/3495491/148657

    $Lookup = @{
        378389 = [version]'4.5'
        378675 = [version]'4.5.1'
        378758 = [version]'4.5.1'
        379893 = [version]'4.5.2'
        393295 = [version]'4.6'
        393297 = [version]'4.6'
        394254 = [version]'4.6.1'
        394271 = [version]'4.6.1'
        394802 = [version]'4.6.2'
        394806 = [version]'4.6.2'
        460798 = [version]'4.7'
        460805 = [version]'4.7'
        461308 = [version]'4.7.1'
        461310 = [version]'4.7.1'
        461808 = [version]'4.7.2'
        461814 = [version]'4.7.2'
        528040 = [version]'4.8'
        528049 = [version]'4.8'
    }
    
    # For One True framework (latest .NET 4x), change the Where-Oject match 
    # to PSChildName -eq "Full":
    Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse |
      Get-ItemProperty -name Version, Release -EA 0 |
      Where-Object { $_.PSChildName -match '^(?!S)\p{L}'} |
      Select-Object @{name = ".NET Framework"; expression = {$_.PSChildName}}, 
    @{name = "Product"; expression = {$Lookup[$_.Release]}}, 
    Version, Release
    

    The above script makes use of the registry and gives us the Windows update number along with .Net Framework installed on a machine.

    Reference: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed#to-find-net-framework-versions-by-querying-the-registry-in-code-net-framework-45-and-later

    Here are the results for the same when running that script on two different machines

    1. Where .NET 4.7.2 was already installed:

    1. Where .NET 4.7.2 was not installed:

提交回复
热议问题