• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 param(
2     [Parameter()]
3     [String]$architecture
4 )
5 
EnterDevShellEnv()6 function EnterDevShellEnv  {
7 
8     param(
9         [Parameter()]
10         [String]$arch
11     )
12 
13     $vsw = Get-Command 'vswhere'
14     $VSFfavors = 'Community','Professional','Enterprise','BuildTools' | %{ "Microsoft.VisualStudio.Product.$_" }
15     $vs = & $vsw.Path -products $VSFfavors -latest -format json | ConvertFrom-Json
16     $tools_dir = Join-Path $vs.installationPath 'Common7' 'Tools'
17     # Try the root tools dir
18     $devshell = Join-Path $tools_dir 'Microsoft.VisualStudio.DevShell.dll'
19     # Try finding it under vsdevshell
20     if (!(Test-Path $devshell -Type Leaf)) {
21         $devshell = Join-Path $tools_dir 'vsdevshell' 'Microsoft.VisualStudio.DevShell.dll'
22     }
23     # Fail if didn't find the DevShell library
24     if (!(Test-Path $devshell -Type Leaf)) {
25         throw "error: cannot find Microsoft.VisualStudio.DevShell.dll"
26     }
27     Import-Module $devshell
28     Enter-VsDevShell -VsInstanceId $vs.instanceId -SkipAutomaticLocation -DevCmdArguments "-arch=$arch -no_logo"
29 }
30 
31 # Enter VsDevShell, capture the environment difference and export it to github env
32 $env_before = @{}
33 Get-ChildItem env: | %{ $env_before.Add($_.Name, $_.Value) }
34 EnterDevShellEnv -arch "$architecture"
35 $env_after = @{}
36 Get-ChildItem env: | %{ $env_after.Add($_.Name, $_.Value) }
37 $env_diff = $env_after.GetEnumerator() | where { -not $env_before.ContainsKey($_.Name) -or $env_before[$_.Name] -ne $_.Value }
38 $env_diff | %{ echo "$($_.Name)=$($_.Value)" >> $env:GITHUB_ENV }
39