人都有每個人嘗試過的VS的自己生成後事件命令行?
嘗試在添加此生成後
@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
如果與像Error 1 The command "@echo off sc query "ServiceName" > nul
等,CTRL-C然後CTRL-V的錯誤信息到記事本中,並期待消息的最後一句消息生成錯誤。它可以是exited with code x
。在這裏查找一些常見錯誤的代碼,看看如何解決它。
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.
更多的錯誤代碼here
,如果有消息生成錯誤這樣
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
打開CMD,然後嘗試用taskkill /fi "services eq ServiceName" /f
先殺死它,如果一切都很好,F5
應該足以對其進行調試。
OOW !!按Ctrl + C然後Ctrl + V,我的意思是新項目。雅只有我在做。是不是可以附加任何進程調試或任何其他選項,而不是單獨的項目。 – PawanS 2011-01-13 10:15:05
當然,這是可能的,但如果您在開發過程中取出服務部分,開發Windows服務會更容易。 – 2011-01-13 10:17:27
嗯......這是很好的方式,但它只是雙打工作。我想其他任何方式都會存在。 – PawanS 2011-01-13 10:26:38