Fix NetStandard issue in System.IO.FileSystem.AccessControl in 5.0 (#42546)
[mono-project.git] / msvc / setup-windows-env.bat
blob7b47754e0b1c95d7e500d99c56a4767e9892f0aa
1 :: Script will setup environment variables directly in callers environment.\r
2 \r
3 :: If we are running from none Windows shell we will need to restore a clean PATH\r
4 :: before setting up VS MSVC build environment. If not there is a risk we will pick up\r
5 :: for example cygwin binaries when running toolchain commands not explicitly setup by\r
6 :: VS MSVC build environment.\r
7 set HKCU_ENV_PATH=\r
8 set HKLM_ENV_PATH=\r
9 if "%SHELL%" == "/bin/bash" (\r
10     for /f "tokens=2,*" %%a in ('%WINDIR%\System32\reg.exe query "HKCU\Environment" /v "Path" ^| %WINDIR%\System32\find.exe /i "REG_"') do (\r
11         SET HKCU_ENV_PATH=%%b\r
12     )\r
13     for /f "tokens=2,*" %%a in ('%WINDIR%\System32\reg.exe query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "Path" ^| %WINDIR%\System32\find.exe /i "REG_"') do (\r
14         SET HKLM_ENV_PATH=%%b\r
15     )\r
16 )\r
18 :: Restore default path, if we are running from none Windows shell.\r
19 if "%SHELL%" == "/bin/bash" (\r
20     call :restore_default_path "%HKCU_ENV_PATH%" "%HKLM_ENV_PATH%"\r
21 )\r
23 :: There is still a scenario where the default path can include cygwin\bin folder. If that's the case\r
24 :: there is still a big risk that build tools will be incorrectly resolved towards cygwin bin folder.\r
25 :: Make sure to adjust path and drop all cygwin paths.\r
26 set NEW_PATH=\r
27 call where /Q "cygpath.exe" && (\r
28     echo Warning, PATH includes cygwin bin folders. This can cause build errors due to incorrectly\r
29     echo located build tools. Build script will drop all cygwin folders from used PATH.\r
30     for %%a in ("%PATH:;=";"%") do (\r
31         if not exist "%%~a\cygpath.exe" (\r
32             call :add_to_new_path "%%~a"\r
33         )\r
34     )\r
35 )\r
37 if not "%NEW_PATH%" == "" (\r
38     set "PATH=%NEW_PATH%"\r
39 )\r
41 exit /b 0\r
43 :restore_default_path\r
45 :: Restore default PATH.\r
46 if not "%~2" == "" (\r
47     if not "%~1" == "" (\r
48         set "PATH=%~2;%~1"\r
49     ) else (\r
50         set "PATH=%~2"\r
51     )\r
52 )\r
54 goto :EOF\r
56 :add_to_new_path\r
58 if "%NEW_PATH%" == "" (\r
59     set "NEW_PATH=%~1"\r
60 ) else (\r
61     SET "NEW_PATH=%NEW_PATH%;%~1"\r
62 )\r
64 goto :EOF