Skip to content

Instantly share code, notes, and snippets.

@crmckenzie
Last active October 8, 2015 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crmckenzie/3363553 to your computer and use it in GitHub Desktop.
Save crmckenzie/3363553 to your computer and use it in GitHub Desktop.
Install-VSCommandPrompt
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