How to modify return code in Visual Studio Build e

2020-03-15 07:46发布

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.

3条回答
地球回转人心会变
2楼-- · 2020-03-15 08:10

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

查看更多
Rolldiameter
3楼-- · 2020-03-15 08:13

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.

查看更多
倾城 Initia
4楼-- · 2020-03-15 08:21

As seen here in the comment of the accepted answer:
Solve "The command "taskkill /F /IM MyApp.vshost.exe" exited with code 128" error

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

taskkill with filter returns no error.

查看更多
登录 后发表回答