我一直在尝试使用构建事件来启动和停止在我的项目中正在构建的Windows服务。但是,预构建和后构建都会因为错误级别255而失败。我已经尝试在预构建时捕获它,但没有成功。
预构建
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
)