How to change return code in Visual Studio Build events

Is it possible to change the return code (I think it is also called errorlevel ) of the command provided in Visual Studio build events?

I run the taskkill /F /IM MyApp.vshost.exe , and I would like this command to return 0 when it actually returns 128 .

+7
source share
3 answers

Redirect all output to temp file and exit with code 0 in the batch file. This will effectively ignore any errors from taskkill :

killit.bat:

 taskkill /F /IM MyApp.vshost.exe > %temp%\out.txt 2>&1 exit /B 0 

Now call killit.bat in the build event.

Refresh After Hege sent his answer, I thought that just pasting the code from the batch file into the build event should also work, because as far as I know, build events in VC are always executed on the command line anyway. And really

 taskkill /F /IM MyApp.vshost.exe > %temp%\out.txt 2>&1 || exit /B 0 

how the build event also works. However, redirection is still required.

+14
source

Try taskkill /F /IM MyApp.vshost.exe || exit /b 0 taskkill /F /IM MyApp.vshost.exe || exit /b 0 .

+2
source

As you can see from the comment of the accepted answer:
Solve the "command" taskkill / F / IM MyApp.vshost.exe "code 128" error

taskkill /F /IM MyApp.vshost.exe /fi "pid gt 0"

taskkill with a filter does not return an error.

+1
source

All Articles