vsvars32.bat in Visual Studio 2017

VS2017 suffers from very seriously brain-damaged install path location choices. Most damning dumb thing they did is to make the edition name (Professional, Enterprise, probably Community) part of the path. This makes it quite difficult to find tools back reliably from one machine to another.

There is one environment variable that I think can solve the problem, the VSAPPIDDIR variable stores the path to the folder where the IDE is installed (devenv.exe). So if you want to run vcvars32.bat from a build event then you'd use

   call "%vsappiddir%..\..\VC\Auxiliary\Build\vcvars32.bat" x86

Note that it is vc, not vs, vsvars32.bat no longer exists. You could possibly favor the "Developer Command Prompt:

   call "%vsappiddir%..\tools\vsdevcmd.bat"

But judging from your link, you actually want to run the editbin.exe utility:

   "%vsappiddir%..\..\VC\Tools\MSVC\14.10.25017\bin\HostX86\x86\editbin.exe" args...

The 14.10.25017 version number is no joy whatsoever either, no real insight in how that is going to change from one update to the next. It probably will.


Just change "vsvars32.bat" to "vsdevcmd.bat". This is compatible at least back to VS2015.

call "$(DevEnvDir)..\tools\vsdevcmd.bat"
editbin /largeaddressaware "$(TargetPath)"

I know the question is (well) answered, but I would like to share how I solved the problem hoping it will help people googling for a solution

@echo off

set INSTALLPATH=

if exist "%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
  for /F "tokens=* USEBACKQ" %%F in (`"%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15.0 -property installationPath`) do set INSTALLPATH=%%F
)

echo INSTALLPATH is "%INSTALLPATH%"

REM Save current dir for later
pushd %CD%

if NOT "" == "%INSTALLPATH%" (
  call "%INSTALLPATH%\Common7\Tools\VsDevCmd.bat"
) else (
  goto ERROR_NO_VS15
)

:WORK
REM Retrieve the working dir and proceed
popd
echo Doing work in %CD%
svcutil this_is_just_an_example
goto END

:ERROR_NO_VS15
echo Visual Studio 2017 Tools Not Available!

:END
echo Processing ends.

A small explanation of the above script.

vswhere.exe is a single-file, native executable you can download or redistribute with your build and deployment environments to locate Visual Studio or other products installed with the new installer for Visual Studio 2017 (from the vswhere wiki)

Starting with Visual Studio 15.2 (26418.1 Preview) vswhere.exe is installed in %ProgramFiles(x86)%\Microsoft Visual Studio\Installer (use %ProgramFiles% in a 32-bit program prior to Windows 10). This is a fixed location that will be maintained (as noted here)

This allows developers to query for several important features of a Visual Studio 2017 (and above) installation. Furthermore, the tool was designed to allow different flavors of Visual Studio (Community Edition, Professional, ...) to be installed on the same machine.

You can find several usage examples here.

As for the script, the first relevant part

if exist "%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
  for /F "tokens=* USEBACKQ" %%F in (`"%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15.0 -property installationPath`) do set INSTALLPATH=%%F
)

Queries vswhere for the installation Path of Visual Studio 2017 (-version 15.0) and sets a variable named INSTALLPATH.

It should be noted that on a 32 bits OS, you should use %programfiles% instead of %programfiles(x86)%.

Due to this issue, the script saves the current directory for later retrieval.

The script then proceeds to test the contents of the INSTALLPATH variable. If the variable is not empty, it appends "Common7\Tools\VsDevCmd.bat" to it (which is a well known relative path where one can find development tools for the corresponding Visual Studio installation). Otherwise, the script jumps to an error message and exits (you may opt to return a non-zero error code).

If all went well, you have now a full fledge Visual Studio development environment at your disposal.

The script now proceeds to retrieve the original directory and execute something, in this case a dummy call to svcutil.