Posted By

zmbq on 03/24/15


Tagged

visual-studio


Versions (?)

Choose a Visual Studio toolset


 / Published in: DOS Batch
 

Choose a Visual Studio toolset from the command prompt. Use: CHOOSE_VS [x64]

Limitations: Supports VS 2010 and up, expects VS to be installed in the standard place (c:\program files (x86)...)

  1. @rem Choose the Visual Studio tools to use
  2. @echo off
  3.  
  4. SETLOCAL EnableDelayedExpansion
  5. REM Part of :colorEcho. See link below
  6. for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  7. set "DEL=%%a"
  8. )
  9.  
  10. @rem Check command line arguments
  11. IF "%1"=="" GOTO BAD_ARGS
  12. SET version=%1
  13.  
  14. SET platform=bad
  15. IF "%2"=="x64" SET platform=amd64
  16. IF "%2"=="" SET platform=
  17. IF "%2"=="x86" SET platform=
  18.  
  19. IF "%platform%"=="bad" GOTO BAD_ARGS
  20.  
  21. @rem Check Visual Studio version
  22. SET display_version=%version%
  23. IF "%version%"=="10" SET display_version=2010
  24. IF "%version%"=="11" SET display_version=2012
  25. IF "%version%"=="12" SET display_version=2013
  26. IF "%version%"=="14" SET display_version=2015
  27. IF "%version%"=="2010" SET version=10
  28. IF "%version%"=="2012" SET version=11
  29. IF "%version%"=="2013" SET version=12
  30. IF "%version%"=="2015" SET version=14
  31. IF "version"=="display_version" GOTO BAD_VERSION
  32.  
  33. SET dir="c:\program files (x86)\microsoft visual studio %version%.0"
  34. SET vcvarsall=%dir%\vc\vcvarsall.bat %platform%
  35. IF NOT EXIST %vcvarsall% GOTO NOT_INSTALLED
  36.  
  37. SET bits=32
  38. IF "%platform%"=="amd64" SET bits=64
  39.  
  40. SET new_title=Visual Studio %display_version% (%bits% bits)
  41. call :colorEcho 0A "Switching to %new_title%"
  42. TITLE %new_title% Command Prompt
  43. ENDLOCAL & SET vcvarsall=%vcvarsall%
  44.  
  45. %vcvarsall%
  46. SET vcvarsall=
  47. EXIT /B 0
  48.  
  49. :BAD_ARGS
  50. ECHO Usage: CHOOSE_VS Version [x64]
  51. ECHO Version is the Visual Studio version (for example 10, 2012, 2015, etc...)
  52. ECHO Specify x64 if you want to use the 64-bit tools.
  53. EXIT /B 1
  54.  
  55. :BAD_VERSION
  56. call :colorEcho 0C "Unsupported Visual Studio version, only 2010 (10), 2012(11), 2013(12) and 2015(14) are supported."
  57. EXIT /B 1
  58.  
  59. :NOT_INSTALLED
  60. call :colorEcho 0C "Visual Studio %display_version% does not seem to be installed."
  61. echo Looked for it at %dir%
  62. EXIT /B 1
  63.  
  64. @REM Taken from here: http://stackoverflow.com/a/21666354/871910
  65. :colorEcho
  66. echo off
  67. <nul set /p ".=%DEL%" > "%~2"
  68. findstr /v /a:%1 /R "^$" "%~2" nul
  69. del "%~2" > nul 2>&1i

Report this snippet  

You need to login to post a comment.