Advertisement
Guest User

VsDevCmd.bat

a guest
Jun 29th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. @if NOT "%VSCMD_DEBUG%" GEQ "3" @echo off
  4.  
  5. @REM If in debug mode, we want to log the environment variable state
  6. @REM prior to VSDevCmd.bat being executed. This is disabled by default
  7. @REM and is enabled by setting [VSCMD_DEBUG] to some value.
  8. if "%VSCMD_DEBUG%" NEQ "" (
  9.         @echo [DEBUG:%~n0] Writing pre-initialization environment to %temp%\dd_vsdevcmd15_preinit_env.log
  10.         set > %temp%\dd_vsdevcmd15_preinit_env.log
  11. )
  12.  
  13. @REM Dump the pre-initialization environment if debug level is 2 or greater (detailed or full trace).
  14. if "%VSCMD_DEBUG%" GEQ "2" (
  15.     @echo [DEBUG:%~nx0] --------------------- VS Developer Command Prompt Environment [pre-init] ---------------------
  16.     set
  17.     @echo [DEBUG:%~nx0] --------------------- VS Developer Command Prompt Environment [pre-init] ---------------------
  18. )
  19.  
  20. @REM script-local error counter
  21. set __vscmd_vsdevcmd_errcount=0
  22.  
  23. @REM Parse the command line and set variables needed.
  24. @REM Need to use this variable instead of passing arguments to escape
  25. @REM the /? option, which will otherwise display the help for 'call'.
  26. set "__VSCMD_ARGS_LIST=%*"
  27. call "%~dp0vsdevcmd\core\vsdevcmd_start.bat"
  28. set __VSCMD_ARGS_LIST=
  29.  
  30. @REM if -? was specified, then help was already printed and we can exit.
  31. if "%VSCMD_ARG_HELP%"=="1" goto :end
  32.  
  33. @REM Set VisualStudioVersion for compatibility with previous revisions of the
  34. @REM VS Developer Command Prompt.
  35. set "VisualStudioVersion=15.0"
  36.  
  37. @REM set the version number to ensure the banner/logo can print it.
  38. @REM We set the version number to the general VS Version (e.g. 15.0)
  39. @REM but will attempt to get a more specific build number from
  40. @REM devenv.exe, if that file is found.
  41. set "VSCMD_VER=15.0"
  42. call :get_vscmd_ver
  43. call :print_vscmd_header
  44.  
  45. if "%VSCMD_DEBUG%" GEQ "2" (
  46.     @echo [DEBUG:%~nx0] -clean_env : %VSCMD_ARG_CLEAN_ENV%
  47.     @echo [DEBUG:%~nx0] -test : %VSCMD_TEST%
  48.     @echo [DEBUG:%~nx0] VS150COMNTOOLS : "%VS150COMNTOOLS%"
  49. )
  50.  
  51. @REM Process scripts 'core' and then 'ext in alphabetical order'.
  52. call :process_core
  53. call :process_ext
  54.  
  55. goto :end
  56.  
  57. @REM ------------------------------------------------------------------------
  58. :process_core
  59.  
  60. @REM *****************************************************************
  61. @REM This section processes known scripts under vsdevcmd\core.
  62. @REM These scripts must be explicitly included in this section to be
  63. @REM called.
  64. @REM
  65. @REM This section should only contain support for components that
  66. @REM are required by environment scripts (i.e. dependencies). All
  67. @REM leaf node scripts should be placed in vsdevcmd\ext, instead.
  68. @REM *****************************************************************
  69.  
  70. @REM *** .NET Framework ***
  71. :core_dotnet
  72. if EXIST "%VS150COMNTOOLS%VsDevCmd\core\dotnet.bat" call :call_script_helper core\dotnet.bat
  73.  
  74. @REM *** msbuild ***
  75. :core_msbuild
  76. if EXIST "%VS150COMNTOOLS%VsDevCmd\core\msbuild.bat" call :call_script_helper core\msbuild.bat
  77.  
  78. @REM *** Windows SDK ***
  79. :core_winsdk
  80. if EXIST "%VS150COMNTOOLS%VsDevCmd\core\winsdk.bat" call :call_script_helper core\winsdk.bat
  81.  
  82. exit /B 0
  83.  
  84. @REM ------------------------------------------------------------------------
  85. :process_ext
  86.  
  87. if "%VSCMD_ARG_NO_EXT%"=="1" (
  88.     if "%VSCMD_DEBUG%" GEQ "1" @echo [DEBUG:%~nx0] Skipping vsdevcmd\ext scripts since -no_ext was specified
  89.     goto :ext_end
  90. )
  91.  
  92. @REM *****************************************************************
  93. @REM This section executes all .bat files found in vsdevcmd\ext.
  94. @REM Any "leaf node" script should be placed in this directory.
  95. @REM A few notes:
  96. @REM * For determinism sake, the scripts are called in alphabetical
  97. @REM   order.
  98. @REM * This section does NOT recursively look in sub-directories
  99. @REM   under vsdevcmd\ext. Sub-directories may be used for
  100. @REM   "implementation detail" scripts called by .bat files in the
  101. @REM   vsdevcmd\ext folder.
  102. @REM *****************************************************************
  103.  
  104. @REM Iterate through ext scripts
  105. if NOT EXIST "%VS150COMNTOOLS%vsdevcmd\ext\" (
  106.     @echo [ERROR:%~nx0] Cannot find 'ext' folder "%VS150COMNTOOLS%vsdevcmd\ext\"
  107.     set /A __vscmd_vsdevcmd_errcount=__vscmd_vsdevcmd_errcount+1
  108.     goto :ext_end
  109. )
  110.  
  111. for /F %%a in ( 'dir "%VS150COMNTOOLS%vsdevcmd\ext\*.bat" /b /a-d-h /on' ) do (
  112.     call :call_script_helper ext\%%a
  113. )
  114.  
  115. :ext_end
  116. set __vscmd_dir_cmd_opt=
  117. exit /B 0
  118.  
  119. @REM ------------------------------------------------------------------------
  120. :call_script_helper
  121. if NOT EXIST "%VS150COMNTOOLS%vsdevcmd\%1" (
  122.     @echo [ERROR:%~nx0] Script "vsdevcmd\%1" could not be found.
  123.     set /A __vscmd_vsdevcmd_errcount=__vscmd_vsdevcmd_errcount+1
  124.     exit /B 1
  125. )
  126.  
  127. if "%VSCMD_TEST%" NEQ "" set __VSCMD_INTERNAL_INIT_STATE=test
  128. if "%VSCMD_ARG_CLEAN_ENV%" NEQ "" set __VSCMD_INTERNAL_INIT_STATE=clean
  129.  
  130. if "%VSCMD_DEBUG%" GEQ "1" @echo [DEBUG:%~nx0] calling "%1"
  131. call "%VS150COMNTOOLS%vsdevcmd\%1"
  132.  
  133. set __VSCMD_INTERNAL_INIT_STATE=
  134.  
  135. if "%ERRORLEVEL%" NEQ "0" (
  136.     if "%VSCMD_DEBUG%" NEQ "" @echo [ERROR:%1] init:FAILED code:%ERRORLEVEL%
  137.  
  138.     set /A __vscmd_vsdevcmd_errcount=__vscmd_vsdevcmd_errcount+1
  139.     exit /B 1
  140. ) else (
  141.     if "%VSCMD_DEBUG%" GEQ "1" @echo [DEBUG:%1] init:COMPLETE
  142. )
  143. exit /B 0
  144.  
  145. :get_vscmd_ver
  146.  
  147. @REM VsDevCmd.bat location: Microsoft Visual Studio 15.0\Common7\Tools
  148. @REM [devenv|wdexpress].isolation.ini location: Microsoft Visual Studio 15.0\Common7\IDE
  149.  
  150. @REM First look for wdexpress.isolation.ini, then devenv.isolation.ini, then fallback to
  151. @REM printing. We look in this order to ensure we can parse only one *.isolation.ini
  152. @REM file. WDExpress has both devenv.isolation.ini and wdexpress.isolation.ini dropped
  153. @REM into Common7\IDE, but only the later (wdexpress.isolation.ini) has the SemanticVersion
  154. @REM specified.
  155.  
  156. set __vscmd_isolation_file=
  157. if EXIST "%VSINSTALLDIR%Common7\IDE\wdexpress.isolation.ini" (
  158.     set "__vscmd_isolation_file=%VSINSTALLDIR%Common7\IDE\wdexpress.isolation.ini"
  159. ) else if EXIST "%VSINSTALLDIR%Common7\IDE\devenv.isolation.ini" (
  160.     set "__vscmd_isolation_file=%VSINSTALLDIR%Common7\IDE\devenv.isolation.ini"
  161. ) else (
  162.     @REM In the "else" case, we'll use the default version number, which comes from the
  163.    @REM Branding file.
  164.    goto :get_vscmd_ver_end
  165. )
  166.  
  167. set __VSCMD_VER=
  168.  
  169. @REM Looking for a line of the form "SemanticVersion=<semver>+<bld>", so we split the
  170. @REM contents of the line on '=' and '+'.
  171. for /F "tokens=1,2,* delims==+" %%A in ('type "%__vscmd_isolation_file%"') do (
  172.    if "%VSCMD_DEBUG%" GEQ "3" @echo [DEBUG:%~nx0] Isolation File: "%%A" , "%%B"
  173.    if /I "%%A" == "SemanticVersion" (
  174.        if "%VSCMD_DEBUG%" GEQ "1" @echo [DEBUG:%~nx0] Found version "%%B"
  175.        set "__VSCMD_VER=%%B"
  176.    )
  177. )
  178.  
  179. if "%__VSCMD_VER%" == "" (
  180.    if "%VSCMD_DEBUG%" GEQ "1" @echo [DEBUG:%~nx0] SemanticVersion not found
  181. ) else (
  182.    if "%VSCMD_DEBUG%" GEQ "2" @echo [DEBUG:%~nx0] "%__vscmd_isolation_file%" found. Setting VSCMD_VER="%VSCMD_VER%".
  183.    set "VSCMD_VER=%__VSCMD_VER%"
  184. )
  185.  
  186. :get_vscmd_ver_end
  187.  
  188. set __vscmd_isolation_file=
  189. set __VSCMD_VER=
  190. exit /B 0
  191.  
  192. @REM ------------------------------------------------------------------------
  193. :print_vscmd_header
  194.  
  195. @REM Allow other Visual Studio command prompts to override the banner text
  196. if "%VSCMD_BANNER_TEXT_ALT%"=="" (
  197.    set "__VSCMD_BANNER_TEXT=Visual Studio 2017 Developer Command Prompt v%VSCMD_VER%"
  198. ) else (
  199.    set "__VSCMD_BANNER_TEXT=%VSCMD_BANNER_TEXT_ALT%"
  200. )
  201.  
  202. if "%VSCMD_ARG_no_logo%"=="" (
  203.    @echo **********************************************************************
  204.    @echo ** %__VSCMD_BANNER_TEXT%
  205.    @echo ** Copyright ^(c^) 2017 Microsoft Corporation
  206.    @echo **********************************************************************
  207. )
  208.  
  209. set __VSCMD_BANNER_TEXT=
  210. exit /B 0
  211.  
  212. @REM ------------------------------------------------------------------------
  213. :end
  214.  
  215. @REM Script clean-up of environment variables used to track
  216. @REM command line options and other state that does not need to
  217. @REM persist past the end of the script.
  218. call "%~dp0vsdevcmd\core\vsdevcmd_end.bat"
  219.  
  220. if "%__vscmd_vsdevcmd_errcount%" NEQ "0" (
  221.    @echo [ERROR:%~nx0] *** VsDevCmd.bat encountered errors. Environment may be incomplete and/or incorrect. ***
  222.    @echo [ERROR:%~nx0] In an uninitialized command prompt, please 'set VSCMD_DEBUG=[value]' and then re-run
  223.    @echo [ERROR:%~nx0] vsdevcmd.bat [args] for additional details.
  224.    @echo [ERROR:%~nx0] Where [value] is:
  225.    @echo [ERROR:%~nx0]    1 : basic debug logging
  226.    @echo [ERROR:%~nx0]    2 : detailed debug logging
  227.    @echo [ERROR:%~nx0]    3 : trace level logging. Redirection of output to a file when using this level is recommended.
  228.    @echo [ERROR:%~nx0] Example: set VSCMD_DEBUG=3
  229.    @echo [ERROR:%~nx0]          vsdevcmd.bat ^> vsdevcmd.trace.txt 2^>^&1
  230.    set __vscmd_vsdevcmd_errcount=
  231.    call :final_log
  232.    exit /B 1
  233. ) else (
  234.    if "%VSCMD_TEST%" NEQ "" @echo [TEST:%~nx0] *** VsDevCmd.bat tests are complete. ***
  235. )
  236.  
  237. set __vscmd_vsdevcmd_errcount=
  238.  
  239. @REM ------------------------------------------------------------------------
  240. :final_log
  241.  
  242. @REM Dump then environment after execution of vsdevcmd.bat.  This is used
  243. @REM for debugging issues with the developer command prompt.  This logging
  244. @REM is disabled by default and will only be enabled by setting of [VSCMD_DEBUG]
  245. @REM in the environment
  246. if "%VSCMD_DEBUG%" NEQ "" (
  247.    @echo [DEBUG:%~n0] Writing post-execution environment to %temp%\dd_vsdevcmd15_env.log
  248.    set > "%temp%\dd_vsdevcmd15_env.log"
  249. )
  250.  
  251. @REM Dump the post-initialization environment if debug level is 2 or greater (detailed or full trace).
  252. if "%VSCMD_DEBUG%" GEQ "2" (
  253.    @echo [DEBUG:%~nx0] --------------------- VS Developer Command Prompt Environment [post-init] ---------------------
  254.    set
  255.    @echo [DEBUG:%~nx0] --------------------- VS Developer Command Prompt Environment [post-init] ---------------------
  256. )
  257.  
  258. exit /B 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement