Swallowing errors in pre-build steps in Visual Studio 2010

被刻印的时光 ゝ 提交于 2019-11-28 07:16:44

I figured it out - you simply need to add the following statement at the end:

SET ERRORLEVEL = 0

or simply:

EXIT 0
Thomas F.

I know this is an old post, but I recently had this issue as well. I wanted to kill the process that I was building if it was currently running, and found that I could do:

taskkill /f /im $(TargetName).exe 2>nul 1>nul
Exit 0

2>nul 1>nul without Exit 0, or vice versa, doesn't seem to work. I have to do both.

Also worth noting this is using Visual Studio Express 2012.

I found the solution when looking into this issue as well on this blog

The 2>nul 1>nul will swallow the stderr and stdout from the command. The EXIT 0 will make sure the build event returns 0.

There is no need to redirrect stdout, just stderr. Also, set errorlevel allows you to have extra lines later if you need. Exit will terminate immediately.

taskkill /f /im:$(TargetFileName) 2>nul &set errorlevel=0

Works in VS 2017.

Wrap your net commands in a batch file and use exit /B 0

http://ss64.com/nt/exit.html

Would embedding the command in an executable that always returns 0 solve your issue?

in c call

system("net stop myservice")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!