Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio pre-build event; Checking exit code for each event

I have a solution with multiple projects. One project only needs to build if both two events, in the pre-build event, exit with error code 0.

So I thought I could do the following:

"C:\Path\To\Binary1.exe" & "C:\path\to\binary2.exe"

In my test scenario something goes wrong so Binary1.exe exits with a non-zero value. But visual studio goes on building the project anyway. When I run the pre-build event commandline in cmd and echo %errorlevel% I see the exit code being non-zero.

When I only put

"C:\Path\To\Binary1.exe"

in the pre-build event, the build is stopped and en error is shown in the Error List window of Visual Studio.

I am definitely sure that Binary1.exe is exiting with a non-zero value as its also shows a messagebox prior to exit.

I can think of one solution. Binary1.exe calling Binary2.exe and exiting with a non-zero exit code when Binary2.exe exits with a non-zero exit code. But that is not really a flexible solution.

To summarize: How can I run multiple pre-build events and stop buidling when one of the commands returns a non-zero value?

like image 997
Mike de Klerk Avatar asked Apr 18 '13 08:04

Mike de Klerk


2 Answers

I think yuou can do as follows:

run command 1
if ERRORLEVEL 1 (
    exit /b 1
    )
run command 2
like image 122
andreikashin Avatar answered Nov 15 '22 03:11

andreikashin


If the two projects are in the same solution, you can set the dependency in Visual studio. Right-click on the solution in the solution explorer and choose "Project Dependencies".

Set the 'last' project to be depending on the first two. In this case Visual studio will build in the right order and will stop building if one of the dependencies fail to build. (Visual Studio 2013)

like image 42
Sammy Avatar answered Nov 15 '22 03:11

Sammy