我一直在尝试使用构建事件来启动和停止在我的项目中构建的 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
)