Getting Your Installer to Register a Service with Wix#

Back to Listing

Getting Your Installer to Register a Service with Wix#

12 May, 2010

We use the amazing TopShelf to setup and configure our windows services. It makes it a snap to install your windows service into the service control manager. Simply issue the following commands against your exe and it is installed or uninstalled:

MyAwesomeService.exe /install MyAwesomeService.exe /uninstall This makes deployment pretty brain dead, but we want to make the process even easier by including a deployment installer. As mentioned previously, creating a installer with Wix# is a snap. And performing actions during the install couldn’t be simpler.

Here is the simple build definition for my current project:

public BuildResult Build()  
    WixObject[] installables = GetInstallables();
    var project = new Project(string.Format(ProductName, buildEnvironment.Version), installables)
                          GUID = ProductId,
                          MSIFileName = string.Format(ProductName, buildEnvironment.Version),
                          UI = WUI.WixUI_ProgressOnly,
                          Manufacturer = Manufacturer,
                          SourceBaseDir = buildEnvironment.OutPutDirectory,
                          AutoAssignedInstallDirPath = InstallPath,
                          Properties = GetProperties(),
                          Actions = GetActions()

    string message = Compiler.BuildMsi(project);

    return new BuildResult { WasSuccessful = true, Message = message };

Notice, I set the project’s Actions property to the value returned by the method GetActions(). This is how I execute my install and uninstall commands during the installation process. The implementation of the method looks like this:

private Action[] GetActions()  
    return new[]
                   new InstalledFileAction("SomeCompany.SomeProduct.Service.exe", "/install", Return.check,
                                           When.After, Step.InstallFinalize, Condition.NOT_Installed),
                   new InstalledFileAction("SomeCompany.SomeProduct.Service.exe", "/uninstall", Return.check,
                                           When.Before, Step.InstallFinalize, Condition.Installed)

And in the words of my good friend and coworker Eric Ridgeway, “That’s hot.”

Share this story

Bobby Johnson

About Author

I am a passionate engineer with an interest in shipping quality software, building strong collaborative teams and continuous improvement of my skills, team and the product.

comments powered by Disqus
Back to top