OpenConsole.psm1: use DevShell module; tidy up for PowerShell 6+ (#9508)

Saw this while snooping around, the gci command on PowerShell core seems
to store the full path in the variable as oppose to just the leaf.

The other modification is to use the PowerShell module that vs ships to
setup the environment.
This commit is contained in:
Luan Vitor Simião Oliveira 2021-03-16 14:29:38 -03:00 committed by GitHub
parent 44f1ba6d4d
commit c5124956a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -41,7 +41,7 @@ function Import-LocalModule
Write-Verbose "$Name already downloaded" Write-Verbose "$Name already downloaded"
$versions = Get-ChildItem "$modules_root\$Name" | Sort-Object $versions = Get-ChildItem "$modules_root\$Name" | Sort-Object
Get-ChildItem -Path "$modules_root\$Name\$($versions[0])\$Name.psd1" | Import-Module Get-ChildItem -Path "$($versions[0].FullName)\$Name.psd1" | Import-Module
} }
} }
@ -74,16 +74,15 @@ function Set-MsbuildDevEnvironment
default { throw "Unknown architecture: $switch" } default { throw "Unknown architecture: $switch" }
} }
$vcvarsall = "$vspath\VC\Auxiliary\Build\vcvarsall.bat" $devShellModule = "$vspath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
Import-Module -Global -Name $devShellModule
Write-Verbose 'Setting up environment variables' Write-Verbose 'Setting up environment variables'
cmd /c ("`"$vcvarsall`" $arch & set") | ForEach-Object { Enter-VsDevShell -VsInstallPath $vspath -SkipAutomaticLocation `
if ($_ -match '=') -devCmdArguments "-arch=$arch" | Out-Null
{
$s = $_.Split("="); Set-Item -Force -path "Env:\Platform" -Value $arch
Set-Item -force -path "env:\$($s[0])" -value "$($s[1])"
}
}
Write-Host "Dev environment variables set" -ForegroundColor Green Write-Host "Dev environment variables set" -ForegroundColor Green
} }