diff --git a/Code/Add-NgenPdbs.ps1 b/Code/Add-NgenPdbs.ps1 index a8ddd52..5b2a01d 100644 --- a/Code/Add-NgenPdbs.ps1 +++ b/Code/Add-NgenPdbs.ps1 @@ -84,47 +84,55 @@ https://github.com/Wintellect/WintellectPowerShell } $vsVersion = $null - $symPath = $symServs["VS 2017"] + $symPath = $symServs["VS 2019"] if ($null -eq $symPath) { - $symPath = $symServs["VS 2015"] + $symPath = $symServs["VS 2017"] if ($null -eq $symPath) { - $symPath = $symServs["VS 2013"] + $symPath = $symServs["VS 2015"] if ($null -eq $symPath) { - # Pull it out of _NT_SYMBOL_PATH. Yes this is only looking at the - # first cache directory specified. - $symPath = $symServs["_NT_SYMBOL_PATH"] + $symPath = $symServs["VS 2013"] if ($null -eq $symPath) { - throw "No symbol server configured" - } - else - { - if ($symPath -match "SRV\*(?[^*]*)\*(?:.*)\;?") + # Pull it out of _NT_SYMBOL_PATH. Yes this is only looking at the + # first cache directory specified. + $symPath = $symServs["_NT_SYMBOL_PATH"] + if ($null -eq $symPath) { - $symPath = $Matches["SymCache"] + throw "No symbol server configured" } else { - throw "_NT_SYMBOL_PATH environment variable does not specify a symbol cache" + if ($symPath -match "SRV\*(?[^*]*)\*(?:.*)\;?") + { + $symPath = $Matches["SymCache"] + } + else + { + throw "_NT_SYMBOL_PATH environment variable does not specify a symbol cache" + } } } + else + { + $vsVersion = "2013" + } } else { - $vsVersion = "2013" + $vsVersion = "2015" } } else { - $vsVersion = "2015" + $vsVersion = "2017" } } else { - $vsVersion = "2017" + $vsVersion = "2019" } if ($null -ne $vsVersion) diff --git a/Code/Import-VisualStudioEnvironment.ps1 b/Code/Import-VisualStudioEnvironment.ps1 index 8ee6375..fbbdf40 100644 --- a/Code/Import-VisualStudioEnvironment.ps1 +++ b/Code/Import-VisualStudioEnvironment.ps1 @@ -36,7 +36,7 @@ VS110COMNTOOLS. .PARAMETER VSVersion The version of Visual Studio you want to use. If left to the default, Latest, the script will look for the latest version of Visual Studio installed on the computer -as the tools to use. Specify 2013, 2015, or 2017 for a specific version. +as the tools to use. Specify 2013, 2015, 2017, or 2019 for a specific version. .PARAMETER Architecture The tools architecture to use. This defaults to the $env:PROCESSOR_ARCHITECTURE @@ -66,7 +66,7 @@ https://github.com/Wintellect/WintellectPowerShell param ( [Parameter(Position=0)] - [ValidateSet("Latest", "2013", "2015", "2017")] + [ValidateSet("Latest", "2013", "2015", "2017", "2019")] [string] $VSVersion = "Latest", [Parameter(Position=1)] [ValidateSet("x86", "amd64", "arm")] @@ -74,6 +74,10 @@ https://github.com/Wintellect/WintellectPowerShell [string]$AdditionalOptions = "" ) + # VS2017+ + $vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + + # for VS2017 and older $versionSearchKey = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7" if ([IntPtr]::size -ne 8) { @@ -87,20 +91,32 @@ https://github.com/Wintellect/WintellectPowerShell if ($VSVersion -eq 'Latest') { - # Find the largest number in the install lookup directory and that will - # be the latest version. - $biggest = 0.0 - Get-RegistryKeyPropertiesAndValues $versionSearchKey | - ForEach-Object { - if ([System.Convert]::ToDecimal($_.Property, [CultureInfo]::InvariantCulture) -gt ` - [System.Convert]::ToDecimal($biggest, [CultureInfo]::InvariantCulture)) - { - $biggest = $_.Property - $vsDirectory = $_.Value - } - } + if (Test-Path -PathType Leaf $vswherePath) + { + $latestVSInfo = & $vswherePath -latest -legacy -format json | ConvertFrom-Json + if ($latestVSInfo) + { + $usingVersion = [System.Convert]::ToDecimal(($latestVSInfo.installationVersion -replace "^(\d+\.\d+)[^\d].*", "`$1"), [CultureInfo]::InvariantCulture) + $vsDirectory = $latestVSInfo.installationPath + } + } + else + { + # Find the largest number in the install lookup directory and that will + # be the latest version. + $biggest = 0.0 + Get-RegistryKeyPropertiesAndValues $versionSearchKey | + ForEach-Object { + if ([System.Convert]::ToDecimal($_.Property, [CultureInfo]::InvariantCulture) -gt ` + [System.Convert]::ToDecimal($biggest, [CultureInfo]::InvariantCulture)) + { + $biggest = $_.Property + $vsDirectory = $_.Value + } + } - $usingVersion = $biggest + $usingVersion = $biggest + } } else { @@ -109,12 +125,22 @@ https://github.com/Wintellect/WintellectPowerShell "2013" { "12.0" } "2015" { "14.0" } "2017" { "15.0" } + "2019" { "16.0" } default { throw "Unknown version of Visual Studio!" } } $usingVersion = [System.Convert]::ToDecimal($propVal, [CultureInfo]::InvariantCulture) - if (Test-PathReg -Path $versionSearchKey -Property $propVal) + if (Test-Path -PathType Leaf $vswherePath) + { + $vsInfo = & $vswherePath -version "[${usingVersion},$($usingVersion + 1))" -legacy -format json | ConvertFrom-Json + if ($vsInfo) + { + $usingVersion = [System.Convert]::ToDecimal(($vsInfo.installationVersion -replace "^(\d+\.\d+)[^\d].*", "`$1"), [CultureInfo]::InvariantCulture) + $vsDirectory = $vsInfo.installationPath + } + } + elseif (Test-PathReg -Path $versionSearchKey -Property $propVal) { $vsDirectory = (Get-ItemProperty -Path $versionSearchKey -WarningAction SilentlyContinue).$propVal } diff --git a/Code/Internal.ps1 b/Code/Internal.ps1 index 149af8c..937b02e 100644 --- a/Code/Internal.ps1 +++ b/Code/Internal.ps1 @@ -93,19 +93,33 @@ function Get-RegistryKeyPropertiesAndValues function LatestVSRegistryKeyVersion { + # 2017+ + $vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" + # 2017 and older $versionSearchKey = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7" if ([IntPtr]::size -ne 8) { $versionSearchKey = "HKLM:\SOFTWARE\Microsoft\VisualStudio\SxS\VS7" } $biggest = 0.0 - Get-RegistryKeyPropertiesAndValues $versionSearchKey | - ForEach-Object { - if ([System.Convert]::ToDecimal($_.Property) -gt [System.Convert]::ToDecimal($biggest)) - { - $biggest = $_.Property - } - } + if (Test-Path -PathType Leaf $vswherePath) + { + $latestVSInfo = & $vswherePath -latest -legacy -format json | ConvertFrom-Json + if ($latestVSInfo) + { + $biggest = [System.Convert]::ToDecimal(($latestVSInfo.installationVersion -replace "^(\d+\.\d+)[^\d].*", "`$1"), [CultureInfo]::InvariantCulture) + } + } + else + { + Get-RegistryKeyPropertiesAndValues $versionSearchKey | + ForEach-Object { + if ([System.Convert]::ToDecimal($_.Property) -gt [System.Convert]::ToDecimal($biggest)) + { + $biggest = $_.Property + } + } + } $biggest } diff --git a/Code/SymbolsSource.ps1 b/Code/SymbolsSource.ps1 index 05dd5ff..7673c32 100644 --- a/Code/SymbolsSource.ps1 +++ b/Code/SymbolsSource.ps1 @@ -14,7 +14,7 @@ Set-StrictMode -version Latest # Script Global Variables ############################################################################### # The array that contains all the versions. -$script:vsVersionArray = "2012", "2013", "2015", "2017" +$script:vsVersionArray = "2012", "2013", "2015", "2017", "2019" ############################################################################### # Module Only Functions