I wrote some Windows services before with Visual Studio 2010, which provided the Visual Studio Setup Project. It had some quirks, but it worked for me. Starting with Visual Studio 2012, Microsoft did not include this project type anymore. Many complaints of the community followed, and in the end they built a VS extension, which brought back the old setup.
There is also (the better way) going with WiX installer (https://wix.codeplex.com), there is even a service template: https://visualstudiogallery.msdn.microsoft.com/7f35c8ce-1763-4340-b720-ab2d359009c5
In this post, however, I will use the new VS setup project extension.
Create Sample Service
♦ File => New => Project…
♦ Visual C# => Windows Desktop => Windows Service
♦ Name: SampleService
♦ “Create directory for solution” checked
♦ In Solution Explorer, select Service1.cs, right-click => Rename
♦ Rename file to SampleService.cs
♦ Select Yes for “… Would you also like to perform a rename …”
SampleService.cs should be shown in Design View now
♦ Click in the background of the designer view
♦ right-click => Add Installer
(serviceProcessInstaller1 and serviceInstaller1 have been added)
♦ open SampleService.cs in design view
♦ in Properties, set ServiceName to SampleService
♦ open ProjectInstaller.cs in Design View
♦ Click serviceInstaller1
♦ In the Properties window, set the ServiceName property to SampleService.
♦ Set the DisplayName property to Sample Service or something else
(This will be shown later in services console as service name)
♦ Here you can also optionlly set StartType from Manual to Automatic
♦ click serviceProcessInstaller1
♦ Edit Account:
Here you can change if the service will run under a technical account (User)
or e.g. as LocalSystem
If you set it as User, a popup during setup will allow user / password to be set
♦ At Solution right-click => Add => New Project…
♦ Other Project Types => Visual Studio Installer => Setup Project
♦ Name: SampleServiceSetup
♦ Select SampleServiceSetup project, right-click => Add => Project Output…
As Project “SampleService => Primary output” should be already selected,
as Configuration “(Active)” should be already selected.
♦ Press OK
♦ Select SampleServiceSetup project, in properties view:
♦ change InstallAllUsers to True
♦ change ProductName to SampleService (remove Setup at the end)
♦ change Title to SampleService (remove Setup at the end)
By default, the target platform of the setup project is x86.
You can change it here to x64 (TargetPlatform)
♦ Right-click the setup project in Solution Explorer => View => Custom Actions
♦ In the Custom Actions view, right-click the Custom Actions node => Add Custom Action…
♦ Double-click the Application Folder in the list to open it,
♦ select Primary Output from SampleService (Active), and click OK.
(“Primary output from SampleService (Active)” was added to the four nodes)
♦ Select SampleServiceSetup project, right-click => View => User Interface
♦ Start => Installation Folder => Properties => InstallAllUsersVisible: change to False
♦ Build solution