title: VC++ 2017 Could not find VC++ tools version "14.16.27023"
body: <p>I've installed Visual 2017 C++ build tools. I am attempting to run <code>vsdevcmd</code> to prepare the environment. But, I am getting an error stating VC++ tools are not installed when they infact are.</p>
  
  <p>Below is the error I am getting:</p>
  
  <pre><code>[DEBUG:vcvars.bat] Could not find VC++ tools version "14.16.27023" under "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\".
  [DEBUG:ext\vcvars.bat] init:COMPLETE
  [DEBUG:core\vsdevcmd_end] initializing with arguments ''
  [ERROR:VsDevCmd.bat] *** VsDevCmd.bat encountered errors. Environment may be incomplete and/or incorrect. ***
  [ERROR:VsDevCmd.bat] In an uninitialized command prompt, please 'set VSCMD_DEBUG=[value]' and then re-run
  [ERROR:VsDevCmd.bat] vsdevcmd.bat [args] for additional details.
  [ERROR:VsDevCmd.bat] Where [value] is:
  [ERROR:VsDevCmd.bat]    1 : basic debug logging
  [ERROR:VsDevCmd.bat]    2 : detailed debug logging
  [ERROR:VsDevCmd.bat]    3 : trace level logging. Redirection of output to a file when using this level is recommended.
  [ERROR:VsDevCmd.bat] Example: set VSCMD_DEBUG=3
  [ERROR:VsDevCmd.bat]          vsdevcmd.bat &gt; vsdevcmd.trace.txt 2&gt;&amp;1
  [DEBUG:VsDevCmd] Writing post-execution environment to C:\Users\KRAFTW~1\AppData\Local\Temp\dd_vsdevcmd15_env.log
  [DEBUG:VsDevCmd.bat] --------------------- VS Developer Command Prompt Environment [post-init] ---------------------
  </code></pre>
  
  <p>Here's the level 3 error reporting of that specific error:</p>
  
  <pre><code>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC&gt;if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\" (
  set "VCToolsInstallDir=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\"
   set "VCToolsVersion=14.16.27023"
  )  else (
  set VCToolsInstallDir=
   if "3" GEQ "2"
   goto :end
  )
  [DEBUG:vcvars.bat] Could not find VC++ tools version "14.16.27023" under "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\".
  </code></pre>
  
  <p>That directory exists because I copied and pasted the path and was able to change into that directory. Using explorer I can also see that exact version does exist, and within it all the expected tools (as can be seen in the image below)</p>
  
  <p><a href="https://i.stack.imgur.com/zUOC0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zUOC0.png" alt="enter image description here"></a></p>
  
  <p>Any ideas what the problem could be?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>As Hans pointed out in the comment there is wild character at the beginning of the filename <code>14.16.27023</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/5R9vx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5R9vx.png" alt="enter image description here"></a></p>
  
  <p>According to the output it's loading the path from here: <code>C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC&gt;set "__VCVARS_DEFAULT_CONFIG_FILE=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"</code></p>
  
  <p>I've inspected this file and it contains the following (no odd character):</p>
  
  <p><a href="https://i.stack.imgur.com/GP1WV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GP1WV.png" alt="enter image description here"></a></p>
  
  <p>Also viewed with a hex editor and there's nothing there:</p>
  
  <p><a href="https://i.stack.imgur.com/bSwtu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bSwtu.png" alt="enter image description here"></a></p>
  
  <p>I inspected the <code>vcdevcmd.bat</code> file and it's failing at this:</p>
  
  <pre><code>@REM *****************************************************************
  @REM This section executes all .bat files found in vsdevcmd\ext.
  @REM Any "leaf node" script should be placed in this directory.
  @REM A few notes:
  @REM * For determinism sake, the scripts are called in alphabetical
  @REM   order.
  @REM * This section does NOT recursively look in sub-directories
  @REM   under vsdevcmd\ext. Sub-directories may be used for
  @REM   "implementation detail" scripts called by .bat files in the
  @REM   vsdevcmd\ext folder.
  @REM *****************************************************************
  
  @REM Iterate through ext scripts
  if NOT EXIST "%VS150COMNTOOLS%vsdevcmd\ext\" (
      @echo [ERROR:%~nx0] Cannot find 'ext' folder "%VS150COMNTOOLS%vsdevcmd\ext\"
      set /A __vscmd_vsdevcmd_errcount=__vscmd_vsdevcmd_errcount+1
      goto :ext_end
  )
  
  for /F %%a in ( 'dir "%VS150COMNTOOLS%vsdevcmd\ext\*.bat" /b /a-d-h /on' ) do (
      call :call_script_helper ext\%%a
  )
  
  :ext_end
  set __vscmd_dir_cmd_opt=
  exit /B 0
  </code></pre>
  
  <p>with the error:</p>
  
  <pre><code>'"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd\ext\"' is not recognized as an internal or external command,
  operable program or batch file.
  [ERROR:ext\] init:FAILED code:1
  </code></pre>
  
  <p>Now I'm not even sure if these 2 errors are related but both appear in the logs. I have attempted complete removed of VS and all of it's products. I've reinstalled with a fresh installer, to no avail.</p>
  
  <p>Thing is, I had this working initially.</p>
  
  <p><strong>Edit 2</strong></p>
  
  <p>Ok, here is the problem with being unable to load VC++ tools (from <code>vcvars.bat</code>):</p>
  
  <pre><code>:export_env_vctoolsinstalldir
  if exist "%VCINSTALLDIR%Tools\MSVC\%__VCVARS_TOOLS_VERSION%\" (
      set "VCToolsInstallDir=%VCINSTALLDIR%Tools\MSVC\%__VCVARS_TOOLS_VERSION%\"
      set "VCToolsVersion=%__VCVARS_TOOLS_VERSION%"
  ) else (
      set VCToolsInstallDir=
      if "%VSCMD_DEBUG%" GEQ "2" @echo [DEBUG:%~nx0] Could not find VC++ tools version "%__VCVARS_TOOLS_VERSION%" under "%VCINSTALLDIR%Tools\MSVC\".
      goto :end
  )
  </code></pre>
  
  <p>I can't find any env. variables set for <code>__VCVARS_TOOLS_VERSION</code> or <code>VCVARS_TOOLS_VERSION</code>. If I could set that, maybe I can get it to work.</p>
  
  <p>Found this at the head of the same file:</p>
  
  <pre><code>if "%__VCVARS_VERSION%" NEQ "" (
      set __VCVARS_TOOLS_VERSION=%__VCVARS_VERSION%
      goto :export_env_vctoolsinstalldir
  )
  </code></pre>
  
  <p>I attempted to set that variable and rerun <code>vcdevcmd</code> but it still failed:</p>
  
  <pre><code>set __VCVARS_VERSION=14.16.27023
  </code></pre>
  
  <p>Also tried:</p>
  
  <pre><code>vsdevcmd -arch=amd64 -host_arch=amd64 -vcvars_ver=14.16.27023
  </code></pre>
  
  <p>That produces the error:</p>
  
  <pre><code>[DEBUG:vcvars.bat] Checking architecture { host , tgt } : { x86 , x86 }
  [DEBUG:vcvars.bat] Could not add directory to PATH: "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCPackages"
  [DEBUG:vcvars.bat] Could not find VC++ tools version "14.16.27023" under "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\".
  [DEBUG:ext\vcvars.bat] init:COMPLETE
  </code></pre>