mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-11-28 14:09:01 +08:00
a5fe308ea3
It works also in cases where scripts/functions are calling each other. Without the $script prefix, it would instead give you the calling function OR the path if there was no parent function. With the prefix, it always yields the directory of the script
53 lines
1.6 KiB
PowerShell
53 lines
1.6 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
|
|
)
|
|
|
|
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
|
|
$vswhereExe = (& $scriptsDir\fetchDependency.ps1 "vswhere") -replace "<sol>::" -replace "::<eol>"
|
|
|
|
$output = & $vswhereExe -prerelease -legacy -products * -format xml
|
|
[xml]$asXml = $output
|
|
|
|
$results = New-Object System.Collections.ArrayList
|
|
foreach ($instance in $asXml.instances.instance)
|
|
{
|
|
$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
|
|
$results.Add("<sol>::${releaseType}::${installationVersion}::${installationPath}::<eol>") > $null
|
|
}
|
|
|
|
# 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))
|
|
{
|
|
return "<sol>::PreferenceWeight1::Legacy::14.0::$installationPath::<eol>"
|
|
}
|
|
}
|
|
|
|
|
|
$results.Sort()
|
|
$results.Reverse()
|
|
|
|
return $results |