-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSet-VsDevEnv.ps1
65 lines (59 loc) · 1.31 KB
/
Set-VsDevEnv.ps1
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
<#
.SYNOPSIS
Invoke the Visual Studio environment batch script. Should alias this with 'vs'
#>
Begin
{
}
Process
{
$script:pushed = $false
$0 = "${env:ProgramFiles}\Microsoft Visual Studio\2022\Professional\Common7\Tools"
if (Test-Path $0)
{
Write-Host '... setting environment for Visual Studio 2022 Professional' -fo DarkYellow
Push-Location $0
$script:pushed = $true
}
else
{
$0 = "${env:ProgramFiles}\Microsoft Visual Studio\2022\Enterprise\Common7\Tools"
if (Test-Path $0)
{
Write-Host '... setting environment for Visual Studio 2022 Enterprise' -fo DarkYellow
Push-Location $0
$script:pushed = $true
}
else
{
Write-Host '... cannot find Visual Studio 2022' -fo Red
return
}
}
# run the VsDevCmd script and then call SET to dump the env...
cmd /c "VsDevCmd.bat & SET" | foreach `
{
$line = $_
# first index only
$index = $line.IndexOf('=')
if ($index -gt 0 -and $index -lt $line.Length - 1)
{
$name = $line.Substring(0, $index)
$value = $line.Substring($index + 1)
$def = (Get-Item env:$name -ea:SilentlyContinue).Value
if ($def -eq $null -or $def -ne $value)
{
Write-Host ('{0,-25}' -f $name) -NoNewline
Write-Host " $value" -fo DarkGray
Set-Item -Force -Path env:$name -Value "$value"
}
}
}
}
End
{
if ($pushed)
{
Pop-Location
}
}