File: EnterDevShell.ps1

package info (click to toggle)
libva 2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,008 kB
  • sloc: ansic: 18,657; xml: 633; makefile: 356; sh: 117; perl: 41
file content (38 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (4)
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
param(
    [Parameter()]
    [String]$architecture
)

function EnterDevShellEnv  {

    param(
        [Parameter()]
        [String]$arch
    )

    $vsw = Get-Command 'vswhere'
    $VSFfavors = 'Community','Professional','Enterprise','BuildTools' | %{ "Microsoft.VisualStudio.Product.$_" }
    $vs = & $vsw.Path -products $VSFfavors -latest -format json | ConvertFrom-Json
    $tools_dir = Join-Path $vs.installationPath 'Common7' 'Tools'
    # Try the root tools dir
    $devshell = Join-Path $tools_dir 'Microsoft.VisualStudio.DevShell.dll'
    # Try finding it under vsdevshell
    if (!(Test-Path $devshell -Type Leaf)) {
        $devshell = Join-Path $tools_dir 'vsdevshell' 'Microsoft.VisualStudio.DevShell.dll'
    }
    # Fail if didn't find the DevShell library
    if (!(Test-Path $devshell -Type Leaf)) {
        throw "error: cannot find Microsoft.VisualStudio.DevShell.dll"
    }
    Import-Module $devshell
    Enter-VsDevShell -VsInstanceId $vs.instanceId -SkipAutomaticLocation -DevCmdArguments "-arch=$arch -no_logo"
}

# Enter VsDevShell, capture the environment difference and export it to github env
$env_before = @{}
Get-ChildItem env: | %{ $env_before.Add($_.Name, $_.Value) }
EnterDevShellEnv -arch "$architecture"
$env_after = @{}
Get-ChildItem env: | %{ $env_after.Add($_.Name, $_.Value) }
$env_diff = $env_after.GetEnumerator() | where { -not $env_before.ContainsKey($_.Name) -or $env_before[$_.Name] -ne $_.Value }
$env_diff | %{ echo "$($_.Name)=$($_.Value)" >> $env:GITHUB_ENV }