Search notes:

Visual Studio: environment variables

The Visual Studio environment variables are needed for the platform toolset to work correctly. They locate and specify

Setting the variables on the command line

Visual Studio 2017 and later

Beginning with Visual Studio 2017, the Visual Studio environment variables are set by VsDevCmd.bat (which extends the functionality of vsvars32.bat of earlier Visual Studio versions).
The directory where VsDevCmd.bat is located can be determined with vswhere.exe, which is (by default) located under C:\Program Files (x86)\Microsoft Visual Studio\Installer:
C:\> "%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -latest -property installationPath
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
Now, with a combination of vswhere.exe and for /f, it is possible to call VsDevCmd.bat in cmd.exe:
C:\> for /f "usebackq delims=#" %a in (`"%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -latest -property installationPath`) do "%a\Common7\Tools\VsDevCmd.bat"
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.7
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
I have created the simple batch file vsenv.bat that does exactly this.
VsDevCmd.bat among others also sets the VSxxxCOMNTOOLS environment variable.
Although in Visual Studio 2017, vsvars32.bat is not under …\Common7\Tools anymore, there is vcvars32.bat (and vcvars64.bat and a few other batch files) under Installation-root\VC\Auxiliiary\Build. (Note: these batch files begin with with vcvars…, not with vsvars…!)
These scripts can be invoked similarly as before:
C:\> for /f "usebackq delims=#" %a in (`"%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -latest -property installationPath`) do "%a\VC\Auxiliary\Build\vcvars32.bat"
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.9.7
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'
See also the vsenv.bat batch file.

Up to Visual Studio 2015

Up to Visual Studio version 2015 (?), the installer set the environment variable %VSxxxCOMNTOOLS% with which it was possible to set the environment variables. The xxx refers to the Visual Studio version (without dots), for example 100, thus the variable being %VS100COMNTOOLS%. The value of the variable points to the Commont7\Tools directory under the respective installation root.
With %VSxxxCOMNTOOLS%, it's possible to locate and run vsvars32.bat, a batch file that sets the necessary environment variables.
Note the apostrophes when using this variable because of the spaces in the path that the variable points at:
C:\> "%VS100COMNTOOLS%\vsvars32.bat"
Setting environment for using Microsoft Visual Studio 2010 x86 tools.

Modifications of these scripts

These script (VsDevCmd.bat etc.) modify and add the following environment variables:

PATH

The __VSCMD_PREINIT_PATH variable contains the value of %PATH% it had prior to adding the Visual Studio variables.

INCLUDE

The INCLUDE directories are not dependent on the 86,64 environment.

LIB

These directories are added to the LIB variable:

LIBPATH

These directories are added to the LIBPATH variable:

Directories

Variables that specify specific directories.
Variable Possible value Comment
VSINSTALLDIR C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\ The Visual Studio installation root-directory. Note the similarity to %VCINSTALLDIR%
VCINSTALLDIR %VSINSTALLDIR%VC\ The VC directory below %VSINSTALLDIR%, it contains the C and C++ specific parts of a Visual Studio installation.
VSxxxCOMNTOOLS %VSINSTALLDIR%Common7\Tools\ xxx corresponds to %VisualStudioVersion% without dot.
DevEnvDir %VSINSTALLDIR%Common7\IDE\ Contains Visual Studio IDE related exes etc, such as devenv.exe.
VCIDEInstallDir %DevEnvDir%VC
VCToolsInstallDir %VCINSTALLDIR%Tools\MSVC\%VCToolsVersion%\
VCToolsRedistDir %VCINSTALLDIR%Redist\MSVC\x.y.z
FrameworkDir32 C:\Windows\Microsoft.NET\Framework\ The location of the .NET Framework
FrameworkDir64 C:\Windows\Microsoft.NET\Framework64\ The location of the .NET Framework
UniversalCRTSdkDir C:\Program Files (x86)\Windows Kits\10\
WindowsSdkDir C:\Program Files (x86)\Windows Kits\10\ Contains include files like <windows.h> under %UniversalCRTSdkDir%\Include\%UCRTVersion%\um or <stdio.h> under %UniversalCRTSdkDir%\Include\%UCRTVersion%\ucrt
WindowsSdkBinPath %WindowsSdkDir%bin
WindowsSdkVerBinPath %WindowsSdkDir%bin\%WindowsSDKVersion%\
WindowsLibPath %WindowsSdkDir%\UnionMetadata\10.0.17763.0;%WindowsSdkDir%\References\10.0.17763.0
ExtensionSdkDir C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs
WindowsSDK_ExecutablePath_x64 C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\
WindowsSDK_ExecutablePath_x86 C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\

Version numbers

Variable name Possible value
Framework40Version v4.0
FrameworkVersion v4.0.30319
FrameworkVersion32 v4.0.30319
FrameworkVersion64 v4.0.30319
UCRTVersion 10.0.17763.0
VSCMD_VER 15.9.7
VisualStudioVersion 15.0
VCToolsVersion 14.16.27023
WindowsSDKVersion 10.0.17763.0\
WindowsSDKLibVersion 10.0.17763.0\
The %FrameworkVersion% variables seem to be used to locate the %SystemRoot%\Microsoft.NET\Framework64\%FrameWorkVersion64% directory.

Environment dependent

Variables that are dependent on the target-bitness
Variable env 32 value env 64 value
Platform x86 x64
FrameworkDir C:\Windows\Microsoft.NET\Framework\ C:\Windows\Microsoft.NET\Framework64\
VSCMD_ARG_HOST_ARCH x86 x64
VSCMD_ARG_TGT_ARCH x86 x64
__DOTNET_PREFERRED_BITNESS 32 64
__DOTNET_ADD_32BIT 1 n/a
__DOTNET_ADD_64BIT n/a 1

Others

Variable name Possible value
CommandPromptType Native
VSCMD_ARG_app_plat Desktop

Index