vcvarsall.bat fails for newly installed Visual Studio 2017

Story

Today I was trying to do some random C++ programming on my own machine. Having done a snippet of code in Visual Studio Code, I fired up VS2015 x64 Native Tools Command Prompt, only to be told to ‘make sure either Visual Studio or C++ Build SKU is installed’.

Actually, I have no reason why I fired up the prompt for 2015 instead of 2017. Perhaps it was because that was the first result of searching ‘command’ in Cortana.

Issue

Condition

  1. You install Visual Studio 2017 Community on Windows 10.
  2. You open VS2015 x64 Native Tools Command Prompt from Start or Cortana.

Symptoms

The script fails, telling you:

Please make sure either Visual Studio or C++ Build SKU is installed.

Expected behaviours

The variables are initialised and the current directory is C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC.

Workaround

Open C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat, the first few lines of which are:

@echo off

REM VC command prompt depends on env. variable installed during VS. This causes VC command prompt to break for C++ Build SKU.
REM So if VS is not installed and C++ Build SKU is installed, set appropriate environment for C++ Build SKU by calling into it's batch file.
REM C++ Build SKU supports only desktop development environment.

if exist "%~dp0..\common7\IDE\devenv.exe" goto setup_VS
if not exist "%~dp0..\common7\IDE\wdexpress.exe" goto setup_buildsku

Insert the following line between the two ifs:

if exist "%~dp0..\..\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe" goto setup_VS

Then save the file. You might have to clear read-only property of the file and need administrator privilege.

Note that some discussions on the Internet (for example, this) suggest that the second if be removed. It works around the issue but is not inherently logical. Removing that if lets the execution fall directly into setup_VS label and works only because we’re lucky. The fix proposed in this entry, however, detects the existence of Visual Studio 2017 and branches accordingly.

Please enable JavaScript to view the comments powered by Disqus.