Trevor Daniel
Trevor Daniel

Reputation: 3974

VS2013 Windows Service - How to make installer?

I have written a Windows Service.

I now want to package it up in an installer.

I have used the VS2013 x86 Native Tools Command Prompt and then used the commands:

To install it:

installutil httpapiservice.exe

To uninstall it:

installutil httpapiservice.exe /u

This works perfectly. I can see the new service in "Services" and stop and start it no problem.

I then proceeded to right click on the project and select "Publish" and it produced a setup.exe

But, when I run the setup.exe I can see it "downloading and extracting" the files. It looks like it's installing but nothing appears in "Services"

Can anyone tell me if I am doing it correctly please?

Thanks

Upvotes: 7

Views: 20502

Answers (4)

James S
James S

Reputation: 3588

You need to add a setup project to your solution to build an installer executable.

Unfortunately Microsoft removed their setup project template from Visual Studio 2012 onwards, which would have done the job.

This means you are stuck with one of the alternatives, which are either less functional, harder to set up, or expensive.

NOTE - scroll down to EDIT 3 for my recommended solution. The rest of this post is just to highlight alternatives.

If you fancy the free route you can add on InstallShield Limited Edition to Visual studio, and use it to create a setup project for your solution. It will work for windows service setup projects in the latest version, but is generally considered pretty rubbish and limited. Here's the instructions for this: link

WiX is a free open source alternative, which is far more functional, but tricky to set up.

EDIT -

Here's an article describing how to use WiX to create a setup project: http://www.schiffhauer.com/wix-template-for-installing-a-windows-service/

EDIT 2 -

As of today (22/04/2014) Microsoft have reinstated the setup project in Visual Studio 2013 as an Visual studio extension - see this post

I've not tried it myself, but it's presumably the same as the VS2010 setup project, which wasn't too hard to learn (and there's plenty of help available on the internet) I'd definately recommend you try this for creating your setup program!

EDIT 3 (Apr 2016) -
I'd highly recommend you use the Visual Studio Installer Projects Extension (as mentioned in the above edit) for creating simple installers for your windows services (and other programs too). The installers it creates are simple, but professional looking enough for simple or small projects.

The extension for Visual Studio 2013 is here
The extension for Visual Studio 2015 is here
The extension for Visual Studio 2017 is here

An article describing how to create a setup project for a windows service using the old VS2010 Setup project is here. Although this is an old article it can be applied directly to the new Installer Project extensions linked above. (Thanks EbbnFlow for the link)

Upvotes: 16

guppy81
guppy81

Reputation: 91

These official Microsoft extensions provide support for Visual Studio Installer Projects in Visual Studio 2013 https://visualstudiogallery.msdn.microsoft.com/9abe329c-9bba-44a1-be59-0fbf6151054d and Visual Studio 2015 https://visualstudiogallery.msdn.microsoft.com/f1cc3f3e-c300-40a7-8797-c509fb8933b9

With these extension and the video in the previous post I was able to make a setup project for a windows service in Visual Studio Community 2015.

Don't forget to add the custom actions for install and uninstall (as described in the video) and also don't forget to add the installer class to your service project to get your service correctly installed under system --> services.

I've added the serviceProcessInstaller and the serviceInstaller-component by code and configured it like this:

public XxxServiceInstaller()
{
    InitializeComponent();

    ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
    ServiceInstaller serviceInstaller = new ServiceInstaller();

    // Service Account Information
    serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
    serviceProcessInstaller.Username = null;
    serviceProcessInstaller.Password = null;

    // Service Information
    serviceInstaller.ServiceName = "your service name";
    serviceInstaller.DisplayName = "your service display name";
    serviceInstaller.StartType = ServiceStartMode.Manual; // or automatic

    this.Installers.Add(serviceProcessInstaller);
    this.Installers.Add(serviceInstaller);

    this.AfterInstall += new InstallEventHandler(ProdSSSyncServiceInstaller_AfterInstall);
}

void XxxServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
{
    ServiceController sc = new ServiceController("your service name");
    // start immediately
    sc.Start();
}

Upvotes: 1

Trevor Daniel
Trevor Daniel

Reputation: 3974

I ended up zipping up the software and including installutil.exe and simply gave the customer instructions have to install and uninstall.

Seems to have worked perfectly.

HTH

Upvotes: 2

tobsen
tobsen

Reputation: 5398

It seems you want to use ClickOnce (publish) to install a service. This isn't possible without a hassle but you can try to do it as described in this answer.

Upvotes: 1

Related Questions