Skip to content

Commit dd27833

Browse files
committed
Fix adding vswhere
1 parent 84f3ead commit dd27833

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

extension/BuildPhpExtension/private/Add-VS.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function Add-Vs {
3333
New-Item -Path $installerDir -ItemType Directory -Force | Out-Null
3434
}
3535
Get-File -Url $vsWhereUrl -OutFile $vswherePath
36+
Add-Path $installerDir
3637
}
3738

3839
$instances = & $vswherePath -products '*' -format json 2> $null | ConvertFrom-Json

php/BuildPhp/BuildPhp.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
# Private functions
6565
'Add-BuildRequirements',
6666
'Add-TestRequirements',
67+
'Add-Path',
6768
'Add-Vs',
6869
'Get-File',
6970
'Get-OciSdk',

php/BuildPhp/private/Add-Path.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Function Add-Path {
2+
<#
3+
.SYNOPSIS
4+
Add a directory to PATH environment variable.
5+
.PARAMETER PathItem
6+
The directory to add to PATH.
7+
#>
8+
[OutputType()]
9+
param(
10+
[Parameter(Mandatory = $true, Position=0, HelpMessage='Path to Add')]
11+
[ValidateNotNull()]
12+
[ValidateLength(1, [int]::MaxValue)]
13+
[string] $PathItem
14+
)
15+
begin {
16+
}
17+
process {
18+
$currentUserPath = [System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::User)
19+
$machinePath = [System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::Machine)
20+
$currentPath = $currentUserPath + ";" + $machinePath
21+
if (-not($currentPath.Split(';').Contains(($PathItem + ";")))) {
22+
$newUserPath = $PathItem + ";" + $currentUserPath
23+
[System.Environment]::SetEnvironmentVariable("PATH", $newUserPath, [System.EnvironmentVariableTarget]::User)
24+
$machinePath = [System.Environment]::GetEnvironmentVariable("PATH", [System.EnvironmentVariableTarget]::Machine)
25+
$env:PATH = $newUserPath + ";" + $machinePath
26+
}
27+
}
28+
end {
29+
}
30+
}

php/BuildPhp/private/Add-VS.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function Add-Vs {
2929
New-Item -Path $installerDir -ItemType Directory -Force | Out-Null
3030
}
3131
Get-File -Url $vsWhereUrl -OutFile $vswherePath
32+
Add-Path $installerDir
3233
}
3334

3435
$instances = & $vswherePath -products '*' -format json 2> $null | ConvertFrom-Json

0 commit comments

Comments
 (0)