1 :: Set up VS msbuild environment depending on installed VS versions.
2 :: Script will setup environment variables directly in callers environment.
4 :: Make sure we can restore current working directory after setting up environment.
5 :: Some of the VS scripts can change the current working directory.
8 :: Get path for current running script.
9 set RUN_SETUP_VS_MSBUILD_ENV_SCRIPT_PATH=%~dp0
11 :: VS2017/VS2019 includes vswhere.exe that can be used to locate current VS installation.
12 set VSWHERE_TOOLS_BIN=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
14 :: Visual Studio 2015 == 14.0
15 if "%VisualStudioVersion%" == "14.0" (
19 :: Visual Studio 2017 == 15.0
20 if "%VisualStudioVersion%" == "15.0" (
24 :: Visual Studio 2019 == 16.0
25 if "%VisualStudioVersion%" == "16.0" (
31 :SETUP_VS_2019_BUILD_TOOLS
33 :: Try to locate VS2019 build tools installation.
34 set VS_2019_BUILD_TOOLS_CMD=%ProgramFiles(x86)%\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\VsMSBuildCmd.bat
36 :: Setup VS2019 VC development environment using build tools installation.
37 call :setup_build_env "%VS_2019_BUILD_TOOLS_CMD%" "%CALLER_WD%" && (
38 set VS_DEFAULT_PLATFORM_TOOL_SET=v142
46 :: Try to locate installed VS2019 VC environment.
47 if exist "%VSWHERE_TOOLS_BIN%" (
48 for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [16.0^,17.0] -prerelease -property installationPath') do (
49 set VS_2019_DEV_CMD=%%a\Common7\Tools\VsMSBuildCmd.bat
53 :: Setup VS2019 VC development environment using VS installation.
54 call :setup_build_env "%VS_2019_DEV_CMD%" "%CALLER_WD%" && (
55 set VS_DEFAULT_PLATFORM_TOOL_SET=v142
61 :SETUP_VS_2017_BUILD_TOOLS
63 :: Try to locate VS2017 build tools installation.
64 set VS_2017_BUILD_TOOLS_CMD=%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsMSBuildCmd.bat
66 :: Setup VS2017 VC development environment using build tools installation.
67 call :setup_build_env "%VS_2017_BUILD_TOOLS_CMD%" "%CALLER_WD%" && (
68 set VS_DEFAULT_PLATFORM_TOOL_SET=v141
76 :: Try to locate installed VS2017 VC environment.
77 if exist "%VSWHERE_TOOLS_BIN%" (
78 for /f "tokens=*" %%a in ('"%VSWHERE_TOOLS_BIN%" -version [15.0^,16.0] -property installationPath') do (
79 set VS_2017_DEV_CMD=%%a\Common7\Tools\VsMSBuildCmd.bat
83 :: Setup VS2017 VC development environment using VS installation.
84 call :setup_build_env "%VS_2017_DEV_CMD%" "%CALLER_WD%" && (
85 set VS_DEFAULT_PLATFORM_TOOL_SET=v141
91 :SETUP_VS_2015_BUILD_TOOLS
93 :: Try to locate VS2015 build tools installation.
94 set VS_2015_BUILD_TOOLS_CMD=%ProgramFiles(x86)%\Microsoft Visual C++ Build Tools\vcbuildtools_msbuild.bat
96 :: Setup VS2015 VC development environment using build tools installation.
97 call :setup_build_env "%VS_2015_BUILD_TOOLS_CMD%" "%CALLER_WD%" && (
98 set VS_DEFAULT_PLATFORM_TOOL_SET=v140
104 :: Try to locate installed VS2015 VC environment.
105 set VS_2015_DEV_CMD=%ProgramFiles(x86)%\Microsoft Visual Studio 14.0\Common7\Tools\VsMSBuildCmd.bat
107 :: Setup VS2015 VC development environment using VS installation.
108 call :setup_build_env "%VS_2015_DEV_CMD%" "%CALLER_WD%" && (
109 set VS_DEFAULT_PLATFORM_TOOL_SET=v140
115 echo Warning, failed to setup VS build environment needed by VS tooling.
116 echo Incomplete build environment can cause build error's due to missing compiler,
117 echo linker and platform libraries.
127 :: Check if VS build environment script exists.
129 goto setup_build_env_error
132 :: Run VS build environment script.
135 :: Restore callers working directory in case it has been changed by VS scripts.
138 goto setup_build_env_exit
140 :setup_build_env_error
143 :setup_build_env_exit