Last active
October 8, 2015 17:18
-
-
Save crmckenzie/3363553 to your computer and use it in GitHub Desktop.
Install-VSCommandPrompt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Install-VSCommandPrompt($version = "2013") | |
{ | |
switch ($version) | |
{ | |
2013 { $toolsVersion = "120" } | |
2012 { $toolsVersion = "110" } | |
2010 { $toolsVersion = "100" } | |
2008 { $toolsVersion = "90" } | |
2005 { $toolsVersion = "80" } | |
default { | |
write-host "'$version' is not a recognized version." | |
return | |
} | |
} | |
#Set environment variables for Visual Studio Command Prompt | |
$variableName = "VS" + $toolsVersion + "COMNTOOLS" | |
$vspath = (get-childitem "env:$variableName").Value | |
$vsbatchfile = "vsvars32.bat"; | |
$vsfullpath = [System.IO.Path]::Combine($vspath, $vsbatchfile); | |
write-host "Loading $variableName from $vsfullpath" | |
#$_ shortcut represents arguments | |
pushd $vspath | |
cmd /c $vsfullpath + "&set" | | |
foreach { | |
if ($_ -match “=”) { | |
$v = $_.split(“=”); | |
set-item -force -path "ENV:\$($v[0])" -value "$($v[1])" | |
} | |
} | |
popd | |
msbuild /version | |
write-host "Visual Studio $version Command Prompt variables set." -ForegroundColor Red | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment