I have this code in my build.bat file
for /R %~dp0 %%A In (*.sln) do (
c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe %%A /t:rebuild /nologo /verbosity:minimal /flp:Verbosity=detailed;LogFile=%~dp0\Logs.txt;append=true /m /p:Configuration=Debug;Platform="Any CPU" /p:VisualStudioVersion="12.0"
if not %errorlevel%==0 set Failed+=1
pause)
My problem is that %errorlevel% always 0 even when log file have errors and warnings.
Comment of JozefZ helped me:
Use either SETLOCAL EnableDelayedExpansion and !errorlevel! instead of %errorlevel% or (better) return to If ErrorLevel 1 syntax. Setting EnabledDelayedExpansion will cause each variable to be expanded at execution time rather than at parse time: parsing, the command interpreter evaluates variables line-by_line and/or command_by_command but all code block in () parentheses considers to be one command. On the other hand, If ErrorLevel 1 should to be read as if ErrorLevel is greater than or equal to 1 thus not equal to 0
Took me a bit to sort this out but this is what worked for me:
msbuild mySolution.sln
if errorlevel 1 exit /b errorlevel
I did not need to use SETLOCAL EnableDelayedExpansion
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With