Thursday, December 5, 2013

Install / uninstall windows service during build for quick debugging

1. Right-click the Windows Service project, choose Properties
2. Click Build Events
3. In pre-build event put:
net stop "PutServiceNameHere"
$(FrameworkDir)\installutil.exe /u $(TargetPath)
Exit /b 0

4. In post-build event put:
$(FrameworkDir)\installutil.exe  $(TargetPath)
net start "PutServiceNameHere"

Now when you build the project it will first stop and uninstall the service, build the exe, then install and start the service. If an error occurs during the build in the post or pre build events look in the Event Viewer > Application log for info on the error.

This works in .NET 3.5.

No comments:

Post a Comment

There was an error in this gadget