-
Notifications
You must be signed in to change notification settings - Fork 35
/
win-vs-env.psm1
48 lines (40 loc) · 1.47 KB
/
win-vs-env.psm1
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
###
# Visual Studio helper functions
###
function Get-VSWhere {
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe";
if (-not (Test-Path $vswhere )) {
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$vswhere = ".\vswhere.exe"
$vswhereApiUri = "https://api.github.com/repos/Microsoft/vswhere/releases/latest"
$tag = (Invoke-RestMethod -Uri $vswhereApiUri)[0].tag_name
$vswhereUri = "https://github.com/Microsoft/vswhere/releases/download/$tag/vswhere.exe"
Invoke-WebRequest -Uri $vswhereUri -OutFile $vswhere | Out-Null
}
return $vswhere
}
function Invoke-Environment
{
Param
(
[Parameter(Mandatory)]
[string]
$Command
)
& "${env:COMSPEC}" /s /c "`"$Command`" -no_logo && set" | Foreach-Object {
if ($_ -match '^([^=]+)=(.*)') {
[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2])
}
}
}
function Get-VSInstallationPath {
$vswhere = Get-VSWhere
$installationPath = & $vswhere -prerelease -legacy -latest -property installationPath
return $installationPath
}
function Invoke-VSDevEnvironment {
Write-Host "Invoke-VSDevEnvironment had been invoked"
$installationPath = Get-VSInstallationPath
$envFilepath = Join-Path $installationPath "Common7\Tools\vsdevcmd.bat"
Invoke-Environment -Command $envFilepath
}