Essayez la ligne de commande d'événement post-build de Visual Studio .
Essayez d'ajouter ceci dans la post-construction:
@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
Si l'erreur de construction avec un message comme celui-ci Error 1 The command "@echo off sc query "ServiceName" > nul
, Ctrl+ Cpuis Ctrl+ Vle message d'erreur dans le Bloc-notes et regardez la dernière phrase du message.
Ça pourrait être dire exited with code x
. Recherchez le code dans une erreur courante ici et voyez comment le résoudre.
1072 -- Marked for deletion → Close all applications that maybe using the service including services.msc and Windows event log.
1058 -- Can't be started because disabled or has no enabled associated devices → just delete it.
1060 -- Doesn't exist → just delete it.
1062 -- Has not been started → just delete it.
1053 -- Didn't respond to start or control → see event log (if logged to event log). It may be the service itself throwing an exception.
1056 -- Service is already running → stop the service, and then delete.
Plus d'informations sur les codes d'erreur ici .
Et si l'erreur de construction avec un message comme celui-ci,
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
ouvrez cmd, puis essayez de le tuer d'abord avec taskkill /fi "services eq ServiceName" /f
Si tout va bien, cela F5devrait suffire à le déboguer.