@echo off
verify # 2>nul
setlocal enableextensions enabledelayedexpansion
if errorlevel 1 goto CANT_SWITCH_ON_EXTENDED_CMD_PROCESSING
call #SETTINGS.cmd
if !errorlevel! neq 0 goto ERROR

if "%~0"=="BUILD_R.cmd" goto START
cls
echo BUILDING "RELEASE" CONFIGURATION:
echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß

:START
set AdditionalKeys=
if not exist "obj\project.assets.json" set AdditionalKeys=!AdditionalKeys! /restore

if "!#UseMsBuild!"=="1" (
call :EXEC_CMD MsBuild /nologo /v:minimal "!#ProjectFileName!" /t:"Build" /p:Configuration="Release"!AdditionalKeys! ) else (
call :EXEC_CMD dotnet build --nologo "!#ProjectFileName!" -t:"Build" -p:Configuration="Release" )
if !errorlevel! neq 0 goto FAILURE

::==================================================================================================

:SUCCESS
if "%~0"=="BUILD_R.cmd" goto FINISH
echo.
echo ÜÜÜ BUILD (RELEASE) ÄÄ SUCCESS ÜÜÜ
goto FINISH

:FAILURE
if "%~0"=="BUILD_R.cmd" goto ERROR
echo.
echo ÜÜÜ ## BUILD (RELEASE) ÄÄ FAILURE ÜÜÜ
goto ERROR

::==================================================================================================

:CANT_SWITCH_ON_EXTENDED_CMD_PROCESSING
echo.
echo ## Can not switch on extended command processing.
goto ERROR

::==================================================================================================

:EXEC_CMD
verify # 2>nul
setlocal enableextensions disabledelayedexpansion
if errorlevel 1 goto CANT_SWITCH_ON_SIMPLE_CMD_PROCESSING_RETURN_ERROR
echo.
echo ^>^> %* ...
%*
if %errorlevel% neq 0 goto END_LOCAL_RETURN_ERROR
goto END_LOCAL_RETURN_SUCCESS

:CANT_SWITCH_ON_SIMPLE_CMD_PROCESSING_RETURN_ERROR
echo.
echo ## Can not switch on simple command processing (without delayed expansion).
goto RETURN_ERROR

::==================================================================================================
:RESET_ERROR
set errorlevel=0
set errorlevel=
goto :EOF
::==================================================================================================
:RETURN_SUCCESS
set errorlevel=0
set errorlevel=
goto :EOF
:RETURN_ERROR
verify # 2>nul
goto :EOF
:END_LOCAL_RETURN_SUCCESS
endlocal
goto RETURN_SUCCESS
:END_LOCAL_RETURN_ERROR
endlocal
goto RETURN_ERROR
::==================================================================================================
:ERROR
if not "%~0"=="BUILD_R.cmd" (
echo 
if not "%$cmd_plain%"=="1" pause )
endlocal
verify # 2>nul
goto :EOF
:FINISH
if not "%~0"=="BUILD_R.cmd" (
echo.
if not "%$cmd_plain%"=="1" pause )
endlocal
call :RESET_ERROR
goto :EOF
::==================================================================================================
