-
-
Save drmohundro/40244009b2f4f32b258b to your computer and use it in GitHub Desktop.
<# | |
.Synopsis | |
Returns the install .NET Framework versions. | |
.Description | |
The script looks through the registry using the notes from the below | |
MSDN links to determine which versions of .NET are installed. | |
- https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx | |
- https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx | |
.Notes | |
AUTHOR: David Mohundro | |
#> | |
$ndpDirectory = 'hklm:\SOFTWARE\Microsoft\NET Framework Setup\NDP\' | |
if (Test-Path "$ndpDirectory\v2.0.50727") { | |
$version = Get-ItemProperty "$ndpDirectory\v2.0.50727" -name Version | select Version | |
$version | |
} | |
if (Test-Path "$ndpDirectory\v3.0") { | |
$version = Get-ItemProperty "$ndpDirectory\v3.0" -name Version | select Version | |
$version | |
} | |
if (Test-Path "$ndpDirectory\v3.5") { | |
$version = Get-ItemProperty "$ndpDirectory\v3.5" -name Version | select Version | |
$version | |
} | |
$v4Directory = "$ndpDirectory\v4\Full" | |
if (Test-Path $v4Directory) { | |
$version = Get-ItemProperty $v4Directory -name Version | select -expand Version | |
$version | |
} |
Just a note: the script doesn't show .Net framework 4.5.2, although I can select it in Visual Studio 2012 / 2015, when creating a new project/solution.
At least this is happening in my case; might be because I've installed the Developer Pack flavor, using Chocolatey ( choco install netfx-4.5.2-devpack ) - I don't know why this might cause issues... but that's what's happening on my station.
I guess this is the desired behavior of the script above, to show only latest 4.6 .Net version ?
So far I didn't find a way to retrieve all .Net frameworks, as they are shown in Visual Studio...
@tibileo You are correct that the devpack is probably the reason it's not showing up. You would probably need to use one of the folder search detection methods to find that version and have it check in the VS program folder since that is probably not a system-wide framework.
Updated to support .NET 4.6 (with Visual Studio 2015 RC).