1

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

3 Answers 3

4

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 
Sign up to request clarification or add additional context in comments.

2 Comments

"not errorlevel 0" is always false, as "errorlevel 0" always true.
This doesn't seem to be working for me. MSBuild always returns an errorlevel of 0 regardless of whether there are errors.
1
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. 

2 Comments

I'm not sure it always returns 1? Not 0 might be safer
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.
1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.