Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support VS2019 in Impor-VisualStudioEnvironment and so on #13

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 24 additions & 16 deletions Code/Add-NgenPdbs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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\*(?<SymCache>[^*]*)\*(?:.*)\;?")
# 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\*(?<SymCache>[^*]*)\*(?:.*)\;?")
{
$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)
Expand Down
58 changes: 42 additions & 16 deletions Code/Import-VisualStudioEnvironment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,14 +66,18 @@ 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")]
[string] $Architecture = ($Env:PROCESSOR_ARCHITECTURE).ToLower(),
[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)
{
Expand All @@ -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
{
Expand All @@ -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
}
Expand Down
28 changes: 21 additions & 7 deletions Code/Internal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Code/SymbolsSource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down