Skip to content

Instantly share code, notes, and snippets.

@mjakeman
Created September 7, 2020 12:33
Show Gist options
  • Save mjakeman/65c78be4532e18ed1618f313596e9a39 to your computer and use it in GitHub Desktop.
Save mjakeman/65c78be4532e18ed1618f313596e9a39 to your computer and use it in GitHub Desktop.
# MSVC Build Tools Access Script
# Adds VC environment variables to the currently active Powershell Shell
# Location of vswhere.exe (at this location since VS 2015.2)
$vswhere = ${env:ProgramFiles(x86)} + "\Microsoft Visual Studio\Installer\vswhere.exe"
# Initialises a new shell with access to the MSVC Build Tools
# From https://github.com/microsoft/vswhere/wiki/Find-VC
$path = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if ($path) {
$path = join-path $path 'Common7\Tools\vsdevcmd.bat'
if (test-path $path) {
cmd /s /c """$path"" $args && set" | Where-Object { $_ -match '(\w+)=(.*)' } | ForEach-Object {
$null = new-item -force -path "Env:\$($Matches[1])" -value $Matches[2]
}
}
}
# Output Message
Write-Output "Initialised Build Environment"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment