Creating Sample Service
Bellow are the steps required to create the sample .NET Service
- Startup Visual Studio, and select the C Sharp node under Project Types. Under Templates, select Windows Service and name the project MyWinService.
- Under Solution Explorer, select the file name Service1.cs, and change it to MyWinService.cs under Properties section.
- Open MyWinService.cs in design mode. Right-Click on the design area and choose Add Installers. This will place two components called ServiceProcessInstaller1 and ServiceInstaller1 onto the design area.
- Select ServiceInstaller1, change its name to MyWinServiceInstaller. Also change the ServiceName from Service1 to MyWinService.
- Select ServiceProcessInstaller1, and change its name to MyWinServiceProcessInstaller.
Create Setup Project
- On the Solution node right click and Add-> New Project.
- In Add New Project dialog, navigate to Project Types->Other Project Types->Setup and Deployment and select Template Setup Project. Set Name to MyWinServiceInstaller.
- Right click on MyWinServiceInstaller and select Add->Project Output.
- In Add Project Output Group dialog select MyWinService Project in the drop down list and select Primary output.
- Create Custom action by right clicking on MyWinServiceInstaller->View->Custom Actions. The Custom Actions tab will appear. Custom actions will install/uninstall the service instead of manually running installutil.
- Right click on Install->Add Custom Action. In the Select Item in Project dialog navigate to Application Folder->Primary output from MyWinService.
- Repeat step 6 for uninstall.
Build install project and install msi.