I Am Not Myself

Bills.Pay(Developer.Skills).ShouldBeTrue()

Getting Your Installer to Register a Service with Wix#

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.”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: