Has anyone tried VS's very own post-build event command line?
try adding this to post-build
@echo off sc query "ServiceName" > nul if errorlevel 1060 goto install goto stop :delete echo delete sc delete "ServiceName" > nul echo %errorlevel% goto install :install echo install sc create "ServiceName" displayname= "Service Display Name" binpath= "$(TargetPath)" start= auto > nul echo %errorlevel% goto start :start echo start sc start "ServiceName" > nul echo %errorlevel% goto end :stop echo stop sc stop "ServiceName" > nul echo %errorlevel% goto delete :end
if there is a build error with a message like Error 1 The command "@echo off sc query "ServiceName" > nul and so on, ctrl-c, then ctrl-v the error message in notepad and see the last sentence of the message.
can say exited with code x . find the code in some common error here and see how to solve it.
1072 -- marked for deletion --> close all apps that maybe using the service including services.msc and windows event log. 1058 -- cant be started because disabled or has no enabled associated devices --> just delete it. 1060 -- doesnt exist --> just delete it. 1062 -- has not been started --> just delete it. 1053 -- didnt response to start or control --> see event log (if logged to event log). it maybe the service itself throw an exception 1056 -- service is already running --> stop the service then delete.
more details about the error here
and if a build error with a message like
Error 11 Could not copy "obj\x86\Debug\ServiceName.exe" to "bin\Debug\ServiceName.exe". Exceeded retry count of 10. Failed. ServiceName Error 12 Unable to copy file "obj\x86\Debug\ServiceName.exe" to "bin\Debug\ServiceName.exe". The process cannot access the file 'bin\Debug\ServiceName.exe' because it is being used by another process. ServiceName
open cmd, then first try killing it taskkill /fi "services eq ServiceName" /f
if all is well, F5 should be sufficient to debug it.
asakura89 Mar 07 '16 at 18:45 2016-03-07 18:45
source share