Sunday, August 23, 2009

Installing a Windows Service project for debugging

You cannot just hit "Debug" project for Windows Service projects in Visual Studio. You need to install the service on the system and then use various debugging techniques (like writing to event log)

1. Add Installer in VS:
  • In the Service [Design] right-click anywhere
  • Click on "Add Installer"
2. Configure "Installer"
  • Click on the ProjectInstaller [Design] and click on serviceProcessInstaller1, choose Properties tab
  • Choose an Account (otherwise you get prompted). Most likely you'll want LocalSystem
  • Click on serviceInstaller1 and choose Properties tab
  • Verify that ServiceName is the correct value (i.e. the name of your service)
3. Create some batch files to automatically install/uninstall it
  • @ECHO Installing
    @SET PATH=%PATH%;C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
    @InstallUtil "path to your service.exe"
    @ECHO Install Done.
    @pause
  • For deleting the service: sc delete MyNewName
4. Now Start it
  • Control Panel -> Administrative Tools -> Services
  • Right-click on your service and Start
Troubleshooting:
1. After you install the service you cannot Build the project. You need to Delete the service first. Luckily you have batch files to rapidly do this for you :)

2. If you are trying to use pop up a message box for debugging purposes you'll get an error. Check your error log to make sure. Click here to read about this

3. Service fails to install. If you previously installed it you'll need to Delete it before you try reinstalling.

References:
1. http://www.dotheweb.net/articles/dotnet/services3.aspx
2. Trial and error

No comments:

Post a Comment

There was an error in this gadget