Skip to content

Instantly share code, notes, and snippets.

@leafgarland
Created October 16, 2014 14:06
Show Gist options
  • Save leafgarland/d101ded11ed485a1371e to your computer and use it in GitHub Desktop.
Save leafgarland/d101ded11ed485a1371e to your computer and use it in GitHub Desktop.
Powershell function to set the Visual Studio command line environment.
function Set-VisualStudioEnvironment {
$command = "$((ls env:\VS*COMNTOOLS | sort | select -last 1).value)vsvars32.bat"
foreach ($line in cmd /c "`"$command`" 2>&1 && set") {
if ($line -match '^([^=]+)=(.*)') {
[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2])
}
}
}
@leafgarland
Copy link
Author

This will select that latest version of VS installed. It could easily be tweaked to allow the selection of specific versions but I haven't needed that.

Set a convenient alias Set-Alias vsvars Set-VisualStudioEnvironment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment