We want to Stop our windows Service before we rebuild it, Then Build the new version, then Copy it to a specified folder (due to the configuration changes putting the exe in different bin folders). then Restart the windows service. It Sounds Simple but the main problem we're having is stopping the service doesn't immediately release the file locks. Causing the build to fail ever other time. (once to stop the service and once to actually copy and restart it)
Currently as stated we do have a way that works exactly 50% of the time. It is however annoying to have to build twice every time we make a change to the solution. The current way is build events on the project level.
The Prebuild Looks like this:
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
net start | find "ServiceHost"
if Not ERRORLEVEL 1 InstallUtil.exe -u
$(ProjectDir)bin\Current\ServiceHost.exe
Exit /b 0
and the PostBuild Looks Like This:
cd $(ProjectDir)bin
DEL Current\* /F /Q /S
xcopy $(Configuration) Current
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
InstallUtil.exe $(ProjectDir)bin\Current\ServiceHost.exe
net start ServiceHost
Exit /b 0
There is also the problem of initial creation of the "Current" Folder as our source control doesn't keep the Bin folder. we could add a mkdir current command in there to fix this. if there is a better way to update the service every build your advice would be appreciated.