我一直在尝试使用生成事件来启动和停止正在建在我的项目的Windows服务。然而对于前期&后构建失败,错误级别255我试着捕捉这种预建,没有运气。事件预生成和后期停止和重新启动Windows服务
预建
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
)
我喜欢有'停止,复制,启动exit'都在生成后,因为服务路径或许不应该直接指向/ bin/Release文件夹。这还可以防止服务被停止,但如果由于其他原因而导致构建失败,则从不重新启动。 – Dan 2013-02-13 18:46:45
@丹有正确的答案。这也可以让你轻松地切换到不同的生成配置,分支等,无需重新安装/重新指定服务。从SDM链接的评论中,您也可以自动安装该服务,以便新开发人员能够正常工作。 – 2014-04-07 17:50:08