gpt4 book ai didi

visual-studio-2010 - 事件构建之前和之后停止和重新启动Windows服务

转载 作者:行者123 更新时间:2023-12-03 14:45:52 25 4
gpt4 key购买 nike

我一直在尝试使用构建事件来启动和停止项目中正在构建的Windows服务。但是,对于pre&post构建,错误级别为255,失败。我试过了运气好的pre-build。

预建

if "$(ConfigurationName)" == "Debug"
(
net stop myService
if errorlevel 2
if errorlevel 255
:exit

:exit
)


建立后

if "$(ConfigurationName)" == "Release"
(
copy $(TargetDir) C:\Media\Bin\$(ProjectName)
if errorlevel 1 BuildEventFailed

:BuildEventFailed
mkdir C:\Media\Bin\$(ProjectName)

copy $(TargetDir) C:\Media\Bin\$(ProjectName)
)
else if "$(ConfigurationName)" == "Debug"
(
net start myService
)

最佳答案

以下Joel Varty的博客提供了我使用的解决方案:
Use Build Events to rebuild a Windows Service without having to manually stop/start it

唯一的问题是当您进行重建时。在生成预生成事件之前,Visual Studio会清理文件。然后,这当然会失败,因为该服务仍在运行。但是常规构建效果很好。希望这可以帮助。

关于visual-studio-2010 - 事件构建之前和之后停止和重新启动Windows服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5301191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com