From bc04d5d75165f3220a4b2cf1f07c95d907777353 Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino Date: Mon, 9 Dec 2019 02:46:13 +0900 Subject: [PATCH 1/4] Add VS2019 as an option --- Code/Add-NgenPdbs.ps1 | 40 +++++++++++++++---------- Code/Import-VisualStudioEnvironment.ps1 | 5 ++-- Code/SymbolsSource.ps1 | 2 +- 3 files changed, 28 insertions(+), 19 deletions(-) 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..0243d38 100644 --- a/Code/Import-VisualStudioEnvironment.ps1 +++ b/Code/Import-VisualStudioEnvironment.ps1 @@ -1,4 +1,4 @@ -#requires -version 5.0 +#requires -version 5.0 ############################################################################### # WintellectPowerShell Module # Copyright (c) 2010-2017 - John Robbins/Wintellect @@ -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")] @@ -109,6 +109,7 @@ https://github.com/Wintellect/WintellectPowerShell "2013" { "12.0" } "2015" { "14.0" } "2017" { "15.0" } + "2019" { "16.0" } default { throw "Unknown version of Visual Studio!" } } 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 From eabd6c0701b00b0cb954d5dd64e3cf17922e6595 Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino Date: Mon, 9 Dec 2019 02:50:44 +0900 Subject: [PATCH 2/4] Use vswhere as defaultVS2017+ contain an utility named vswhere, which discovers installed VS's.VS2019 abolished the registry that contains the infomation of the installed version. --- Code/Import-VisualStudioEnvironment.ps1 | 55 ++++++++++++++++++------- Code/Internal.ps1 | 28 +++++++++---- 2 files changed, 61 insertions(+), 22 deletions(-) diff --git a/Code/Import-VisualStudioEnvironment.ps1 b/Code/Import-VisualStudioEnvironment.ps1 index 0243d38..fc21b4c 100644 --- a/Code/Import-VisualStudioEnvironment.ps1 +++ b/Code/Import-VisualStudioEnvironment.ps1 @@ -1,4 +1,4 @@ -#requires -version 5.0 +#requires -version 5.0 ############################################################################### # WintellectPowerShell Module # Copyright (c) 2010-2017 - John Robbins/Wintellect @@ -74,6 +74,10 @@ https://github.com/Wintellect/WintellectPowerShell [string]$AdditionalOptions = "" ) + # VS2017+ + $vswherePath = "C:\Program Files (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 { @@ -115,7 +131,16 @@ https://github.com/Wintellect/WintellectPowerShell $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..3ff12c7 100644 --- a/Code/Internal.ps1 +++ b/Code/Internal.ps1 @@ -93,19 +93,33 @@ function Get-RegistryKeyPropertiesAndValues function LatestVSRegistryKeyVersion { + # 2017+ + $vswherePath = "C:\Program Files (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 } From cb9a44115f5cedcccbb773285e90c66ad4967981 Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino Date: Thu, 19 Dec 2019 17:34:56 +0900 Subject: [PATCH 3/4] Generalize path of Program Files --- Code/Import-VisualStudioEnvironment.ps1 | 4 ++-- Code/Internal.ps1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Code/Import-VisualStudioEnvironment.ps1 b/Code/Import-VisualStudioEnvironment.ps1 index fc21b4c..eb4f19f 100644 --- a/Code/Import-VisualStudioEnvironment.ps1 +++ b/Code/Import-VisualStudioEnvironment.ps1 @@ -1,4 +1,4 @@ -#requires -version 5.0 +#requires -version 5.0 ############################################################################### # WintellectPowerShell Module # Copyright (c) 2010-2017 - John Robbins/Wintellect @@ -75,7 +75,7 @@ https://github.com/Wintellect/WintellectPowerShell ) # VS2017+ - $vswherePath = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" + $vswherePath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" # for VS2017 and older $versionSearchKey = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7" diff --git a/Code/Internal.ps1 b/Code/Internal.ps1 index 3ff12c7..937b02e 100644 --- a/Code/Internal.ps1 +++ b/Code/Internal.ps1 @@ -94,7 +94,7 @@ function Get-RegistryKeyPropertiesAndValues function LatestVSRegistryKeyVersion { # 2017+ - $vswherePath = "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" + $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) From 6d4cbc96a78f453a38bafddebdd7e22c6905040c Mon Sep 17 00:00:00 2001 From: Tatsunori Uchino Date: Thu, 19 Dec 2019 17:35:24 +0900 Subject: [PATCH 4/4] Fix parameter help --- Code/Import-VisualStudioEnvironment.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Code/Import-VisualStudioEnvironment.ps1 b/Code/Import-VisualStudioEnvironment.ps1 index eb4f19f..fbbdf40 100644 --- a/Code/Import-VisualStudioEnvironment.ps1 +++ b/Code/Import-VisualStudioEnvironment.ps1 @@ -1,4 +1,4 @@ -#requires -version 5.0 +#requires -version 5.0 ############################################################################### # WintellectPowerShell Module # Copyright (c) 2010-2017 - John Robbins/Wintellect @@ -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