Swallowing errors in pre-build steps in Visual Studio 2010

前端 未结 6 2050
情话喂你
情话喂你 2020-12-08 14:02

My solution has a bunch of projects one of which is a windows service; I have a prebuild step to stop the service and a postbuild step to restart it (this way the windows se

6条回答
  •  萌比男神i
    2020-12-08 14:05

    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.

提交回复
热议问题