aboutsummaryrefslogtreecommitdiff
path: root/scripts/getVisualStudioInstances.ps1
blob: 910d0f98b65aa016640c76feb1e557055039340e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
[CmdletBinding()]
param(

)
Set-StrictMode -Version Latest
$scriptsDir = split-path -parent $script:MyInvocation.MyCommand.Definition
. "$scriptsDir\VcpkgPowershellUtils.ps1"

$programFiles = getProgramFiles32bit

$results = New-Object System.Collections.ArrayList

$vswhereExe = "$programFiles\Microsoft Visual Studio\Installer\vswhere.exe"

if (Test-Path $vswhereExe)
{
    $output = & $vswhereExe -prerelease -legacy -products * -format xml
    [xml]$asXml = $output

    foreach ($instance in $asXml.instances.instance)
    {
        $installationPath = $instance.InstallationPath -replace "\\$" # Remove potential trailing backslash
        $installationVersion = $instance.InstallationVersion

        $isPrerelease = -7
        if (vcpkgHasProperty -object $instance -propertyName "isPrerelease")
        {
            $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
    }
}
else
{
    Write-Verbose "Could not locate vswhere at $vswhereExe"
}

if ("$env:vs140comntools" -ne "")
{
    $installationPath = Split-Path -Parent $(Split-Path -Parent "$env:vs140comntools")
    $clExe = "$installationPath\VC\bin\cl.exe"
    $vcvarsallbat = "$installationPath\VC\vcvarsall.bat"

    if ((Test-Path $clExe) -And (Test-Path $vcvarsallbat))
    {
        $results.Add("<sol>::PreferenceWeight1::Legacy::14.0::$installationPath::<eol>") > $null
    }
}

$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))
{
    $results.Add("<sol>::PreferenceWeight1::Legacy::14.0::$installationPath::<eol>") > $null
}

$results.Sort()
$results.Reverse()

return $results