1
- # requires -version 5.0
1
+ # requires -version 5.0
2
2
# ##############################################################################
3
3
# WintellectPowerShell Module
4
4
# Copyright (c) 2010-2017 - John Robbins/Wintellect
@@ -74,6 +74,10 @@ https://github.com/Wintellect/WintellectPowerShell
74
74
[string ]$AdditionalOptions = " "
75
75
)
76
76
77
+ # VS2017+
78
+ $vswherePath = " C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
79
+
80
+ # for VS2017 and older
77
81
$versionSearchKey = " HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7"
78
82
if ([IntPtr ]::size -ne 8 )
79
83
{
@@ -87,20 +91,32 @@ https://github.com/Wintellect/WintellectPowerShell
87
91
88
92
if ($VSVersion -eq ' Latest' )
89
93
{
90
- # Find the largest number in the install lookup directory and that will
91
- # be the latest version.
92
- $biggest = 0.0
93
- Get-RegistryKeyPropertiesAndValues $versionSearchKey |
94
- ForEach-Object {
95
- if ([System.Convert ]::ToDecimal($_.Property , [CultureInfo ]::InvariantCulture) -gt `
96
- [System.Convert ]::ToDecimal($biggest , [CultureInfo ]::InvariantCulture))
97
- {
98
- $biggest = $_.Property
99
- $vsDirectory = $_.Value
100
- }
101
- }
94
+ if (Test-Path - PathType Leaf $vswherePath )
95
+ {
96
+ $latestVSInfo = & $vswherePath - latest - legacy - format json | ConvertFrom-Json
97
+ if ($latestVSInfo )
98
+ {
99
+ $usingVersion = [System.Convert ]::ToDecimal(($latestVSInfo.installationVersion -replace " ^(\d+\.\d+)[^\d].*" , " `$ 1" ), [CultureInfo ]::InvariantCulture)
100
+ $vsDirectory = $latestVSInfo.installationPath
101
+ }
102
+ }
103
+ else
104
+ {
105
+ # Find the largest number in the install lookup directory and that will
106
+ # be the latest version.
107
+ $biggest = 0.0
108
+ Get-RegistryKeyPropertiesAndValues $versionSearchKey |
109
+ ForEach-Object {
110
+ if ([System.Convert ]::ToDecimal($_.Property , [CultureInfo ]::InvariantCulture) -gt `
111
+ [System.Convert ]::ToDecimal($biggest , [CultureInfo ]::InvariantCulture))
112
+ {
113
+ $biggest = $_.Property
114
+ $vsDirectory = $_.Value
115
+ }
116
+ }
102
117
103
- $usingVersion = $biggest
118
+ $usingVersion = $biggest
119
+ }
104
120
}
105
121
else
106
122
{
@@ -115,7 +131,16 @@ https://github.com/Wintellect/WintellectPowerShell
115
131
116
132
$usingVersion = [System.Convert ]::ToDecimal($propVal , [CultureInfo ]::InvariantCulture)
117
133
118
- if (Test-PathReg - Path $versionSearchKey - Property $propVal )
134
+ if (Test-Path - PathType Leaf $vswherePath )
135
+ {
136
+ $vsInfo = & $vswherePath - version " [${usingVersion} ,$ ( $usingVersion + 1 ) )" - legacy - format json | ConvertFrom-Json
137
+ if ($vsInfo )
138
+ {
139
+ $usingVersion = [System.Convert ]::ToDecimal(($vsInfo.installationVersion -replace " ^(\d+\.\d+)[^\d].*" , " `$ 1" ), [CultureInfo ]::InvariantCulture)
140
+ $vsDirectory = $vsInfo.installationPath
141
+ }
142
+ }
143
+ elseif (Test-PathReg - Path $versionSearchKey - Property $propVal )
119
144
{
120
145
$vsDirectory = (Get-ItemProperty - Path $versionSearchKey - WarningAction SilentlyContinue).$propVal
121
146
}
0 commit comments