如何修改Visual Studio Build事件中的返回代码 [英] How to modify return code in Visual Studio Build events
问题描述
是否可以修改在Visual Studio的Build事件中提交的命令的返回代码(我认为它也被称为 errorlevel
)?
我运行命令 taskkill / F / IM MyApp.vshost.exe
,我希望这个命令返回<$ c $当 128
将所有输出重定向到临时文件,并在批处理文件中以代码0退出。这将有效地忽略来自 taskkill
的任何错误:
killit.bat:
taskkill / F / IM MyApp.vshost.exe> %temp%\out.txt 2>& 1
exit / B 0
现在在构建事件中调用killit.bat。
更新后发布他的答案,我想把粘贴的代码从批处理文件构建事件应该工作,因为我的理解,VC中的构建事件总是在命令行上执行。确实
taskkill / F / IM MyApp.vshost.exe> %temp%\out.txt 2>& 1 || exit / B 0
仍然需要重定向。
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
.
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.
这篇关于如何修改Visual Studio Build事件中的返回代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!