diff --git a/src/tools/msvc/build.bat b/src/tools/msvc/build.bat
index fe736dde471f6d79b20778a53e0b217fc952cbc3..4f586b69a02ca4c4a7a9fe7b1544f550fdc02d0a 100755
--- a/src/tools/msvc/build.bat
+++ b/src/tools/msvc/build.bat
@@ -17,5 +17,8 @@ if "%CONFIG%" == "" set CONFIG=Debug
 
 if "%1" == "" msbuild pgsql.sln /verbosity:detailed /p:Configuration=%CONFIG%
 if not "%1" == "" vcbuild %1.vcproj %CONFIG%
+SET E=%ERRORLEVEL%
 
 cd %STARTDIR%
+
+exit /b %E%