views:

398

answers:

3

I am trying to build multiple .sln files inside a batch file. Everything works great so far. I am trying to add a check inside the batch file, so if number of errors is greater than 0 then the batch file stops executing and doesn't build the next .sln files. How can I do that? Basically something like:

msbuild test.sln (check if build error > 0 stop) msbuild test2.sln

+4  A: 

MSBUILD will set the ERRORLEVEL, so something along the lines of:

msbuild test.sln
IF NOT ERRORLEVEL 0 exit 1

Edit: Apparently it should be:

msbuild test.sln
IF ERRORLEVEL 1 exit 1
Steven Robbins
"not errorlevel 0" is always false, as "errorlevel 0" always true.
Srdjan Jovcic
+1  A: 
msbuild.exe test.sln
if errorlevel 1 goto :errors

msbuild.exe test2.sln
if errorlevel 1 goto :errors

:: ...

:: Everything was fine.
echo Build completed without errors.
goto :eof

:error
echo Build failed.
Srdjan Jovcic
I'm not sure it always returns 1? Not 0 might be safer
Steven Robbins
if errorlevel 1 will be true if errorlevel is 1 or _higher_:IF [NOT] ERRORLEVEL number command ERRORLEVEL number Specifies a true condition if the last program run returned an exit code equal to or greater than the number specified.
Srdjan Jovcic
A: 

In my opinion it's much easier to use a custom msbuild file here and use the msbuild task with your set of solutions. See here for the details.

Bas Bossink