2017-01-23 12:53:18 -08:00
|
|
|
[CmdletBinding()]
|
|
|
|
param(
|
|
|
|
|
|
|
|
)
|
|
|
|
|
2018-01-22 18:18:53 -08:00
|
|
|
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
|
2017-10-31 17:23:09 -07:00
|
|
|
$vswhereExe = (& $scriptsDir\fetchDependency.ps1 "vswhere") -replace "<sol>::" -replace "::<eol>"
|
2017-01-23 12:53:18 -08:00
|
|
|
|
2017-10-09 16:38:21 -07:00
|
|
|
$output = & $vswhereExe -prerelease -legacy -products * -format xml
|
2017-10-05 18:25:34 -07:00
|
|
|
[xml]$asXml = $output
|
2017-01-23 12:53:18 -08:00
|
|
|
|
2017-10-05 18:25:34 -07:00
|
|
|
$results = New-Object System.Collections.ArrayList
|
|
|
|
foreach ($instance in $asXml.instances.instance)
|
2017-01-23 12:53:18 -08:00
|
|
|
{
|
2017-10-05 18:25:34 -07:00
|
|
|
$installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash
|
|
|
|
$installationVersion = $instance.InstallationVersion
|
|
|
|
$isPrerelease = $instance.IsPrerelease
|
|
|
|
if ($isPrerelease -eq 0)
|
|
|
|
{
|
|
|
|
$releaseType = "PreferenceWeight3::StableRelease"
|
|
|
|
}
|
|
|
|
elseif ($isPrerelease -eq 1)
|
|
|
|
{
|
|
|
|
$releaseType = "PreferenceWeight2::PreRelease"
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$releaseType = "PreferenceWeight1::Legacy"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Placed like that for easy sorting according to preference
|
2017-10-31 17:06:07 -07:00
|
|
|
$results.Add("<sol>::${releaseType}::${installationVersion}::${installationPath}::<eol>") > $null
|
2017-01-23 12:53:18 -08:00
|
|
|
}
|
|
|
|
|
2017-10-16 17:04:55 -07:00
|
|
|
# If nothing is found, attempt to find VS2015 Build Tools (not detected by vswhere.exe)
|
|
|
|
if ($results.Count -eq 0)
|
|
|
|
{
|
|
|
|
$programFiles = & $scriptsDir\getProgramFiles32bit.ps1
|
|
|
|
$installationPath = "$programFiles\Microsoft Visual Studio 14.0"
|
|
|
|
$clExe = "$installationPath\VC\bin\cl.exe"
|
|
|
|
$vcvarsallbat = "$installationPath\VC\vcvarsall.bat"
|
|
|
|
|
|
|
|
if ((Test-Path $clExe) -And (Test-Path $vcvarsallbat))
|
|
|
|
{
|
2017-10-31 17:06:07 -07:00
|
|
|
return "<sol>::PreferenceWeight1::Legacy::14.0::$installationPath::<eol>"
|
2017-10-16 17:04:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-05 18:25:34 -07:00
|
|
|
$results.Sort()
|
|
|
|
$results.Reverse()
|
2017-01-23 12:53:18 -08:00
|
|
|
|
2017-10-05 18:25:34 -07:00
|
|
|
return $results
|