Is it possible to modify the return code (I think it is also called errorlevel
) of a command submitted in the Build events of Visual Studio?
I am running the command taskkill /F /IM MyApp.vshost.exe
and I would like this command to return 0
when it is in fact returning 128
.
In the Post-build event command line box, specify the syntax of the build event. Add a call statement before all post-build commands that run . bat files. For example, call C:\MyFile.
Another way is to check the bin\debug dir for 'PreBuildEvent. bat' or 'PostBuildEvent. bat' which are the file that Visual Studio creates and run during the build events, if there is an error the files remain in the output dir and you can run them manually and spot the error.
Go to Solution Explorer and right-click on the project then select Properties then go to the Build Events tab.
Pre/Post build events are useful when we wish to perform some operation before/after a project is built. These operations are nothing but the Shell commands being used from the command line. A build event can be formed using a single, multiple, or conditional commands. Introduction.
Redirect all output to a temp file and exit with code 0, in a 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 invoke killit.bat in the build event.
Update After hege posted his answer I figured just pasting the code from the batch file into the build event should work as well, since to my understanding build events in VC are always executed on the command line anyway. And indeed
taskkill /F /IM MyApp.vshost.exe > %temp%\out.txt 2>&1 || exit /B 0
as a build event works as well. The redirection is still required though.
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