Visual Studio 2010 中预构建步骤中的吞咽错误
我的解决方案有很多项目,其中一个是 Windows 服务;我有一个预构建步骤来停止服务,还有一个后构建步骤来重新启动它(这样,当 VS 构建/覆盖它时,Windows 服务 exe 不会被锁定)。
on pre-build:
net stop myservice
on post-build:
net start myservice
如果在我开始构建时该服务未运行,则 net stop 命令将失败并阻止构建继续进行。
即使预构建步骤失败,我该怎么做才能仍然强制构建?
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 service exe is not locked when VS is building/overwriting it).
on pre-build:
net stop myservice
on post-build:
net start myservice
If the service is not running while I'm starting the build, the net stop command fails and that prevents the build from proceeding.
What can I do to still force the build even if the pre-build step failed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我想通了 - 你只需要在末尾添加以下语句:
或者简单地:
I figured it out - you simply need to add the following statement at the end:
or simply:
我知道这是一篇旧帖子,但我最近也遇到了这个问题。我想终止我正在构建的进程(如果它当前正在运行),并发现我可以执行:
2>nul 1>nul
而无需Exit 0
,反之亦然,似乎不起作用。我必须两者都做。另外值得注意的是,这是使用 Visual Studio Express 2012。
我在研究这个问题时也找到了解决方案 在此博客上
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:
2>nul 1>nul
withoutExit 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
不需要重定向 stdout,只需重定向 stderr。此外,如果需要,
set errorlevel
允许您稍后添加额外的行。退出将立即终止。taskkill /f /im:$(TargetFileName) 2>nul &set errorlevel=0
适用于 VS 2017。
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.
有点晚了,但这是一个很好的解决方案,所以无论如何我都会分享它。
以下解决方案取自此 博客文章。
您只需根据需要定义您的例如构建后步骤。您不需要将它们包装到批处理文件中,但您可以。然后,更改项目文件(例如 vbproj 或 csproj 文件)并在项目结束标记之前插入以下片段:
这会更改 Visual Studio 执行构建后步骤的方式。 ContinueOnError 属性指示 VS 简单地忽略错误。它仍然在构建结果中发出警告,但不会停止构建。
您可以通过相应地更改上述片段来对 PreBuildEvent 执行相同的操作。
当然,这仅适用于完整的所有构建步骤。您不能选择性地仅忽略某些步骤上的错误。如果您需要这样做,则必须坚持使用批处理文件的解决方案,但上述解决方案的好处是您不需要单独的批处理。
萨沙
A bit late, but a good solution, so I'll share it anyway.
The following solution was taken from this blog post.
You simply define your e.g. post build steps as needed. You don't need to wrap them into a batch file, but you could. Then you alter you project file (such as a vbproj or csproj file) and insert the following fragment just before the project closing-tag:
This changes the way visual studio executes the post build steps. The ContinueOnError Attributes instructs VS to simply ignore errors. It still issues warnings in the build results, but it does not stop the build.
You can do the same for the PreBuildEvent by changing the above fragment accordingly.
Of course this works only for all of the build steps in full. You can not selectivly ignore errors on certain steps only. If you need to do that you have to stick to the solution with the batch file, but the nice thing about the solution above is you don't need a separate batch.
Sascha
将
net
命令封装在批处理文件中并使用exit /B 0
http://ss64.com/nt/exit.html
Wrap your
net
commands in a batch file and useexit /B 0
http://ss64.com/nt/exit.html
将命令嵌入到始终返回 0 的可执行文件中是否可以解决您的问题?
在c调用中
Would embedding the command in an executable that always returns 0 solve your issue?
in c call