C# – Wix MSI package : for Windows service

cwindowswindows-installerwindows-serviceswix

Error : Creating new installer using WiX toolset, for windows service. Not able to install the service. Getting an error
Error screenshot

Environment

  • Microsoft visual studio 2017
  • Windows 7
  • WiX toolset v3 : Setup project for MSI

Problem/Goal

I want to create a MSI which installs a Windows service.

On Install :

Windows service gets installed and visible in services.msc

On UnInstall:

Stop and Remove the service.

My windows service has lot of dependencies which are to be used when running the service.

I have added all the files as component and added ServiceDependency for each of the component ID also, but still not able to resolve the error. The error in the event viewer is also the same as the above screenshot.

Any pointers are most welcome.

My Code

    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <Feature Id="ProductFeature" Title="LayoutSwitcher" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
    </Feature>
</Product>

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="LayoutSwitcher" />
        </Directory>
    </Directory>
</Fragment>

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">

  <Component Id="PlcmLayoutSwitcherWinSvc.exe" Guid="PUT_GUID_HERE" KeyPath="yes">
            <File Id="LayoutSwitcherWinSvc.exe" 
 Name="LayoutSwitcherWinSvc.exe" Source="$(var.LayoutSwitcherWinSvc_TargetDir)LayoutSwitcherWinSvc.exe" />

    <CreateFolder />
    <ServiceInstall Id="LayoutSwitcher" Type="ownProcess" Vital="yes" 
                    Name="LayoutSwitcher" DisplayName="LayoutSwitcher" 
                    Description="LayoutSwitcher" Start="auto" Account="NT AUTHORITY\LocalSystem" 
                    ErrorControl="ignore" Interactive="no">
   <ServiceControl Id="StartService" Start="install" Stop="both" 
    Remove="uninstall" Name="LayoutSwitcher" Wait="yes" />
  </Component>
    <Component Id="logoicon.ico" Guid="PUT_GUID_HERE">
        <File Id="logoicon.ico" Name="logoicon.ico" Source="$(var.LayoutSwitcherWinSvc_ProjectDir)logoicon.ico" />
     </Component>
     <Component Id="LayoutSwitcherWinSvc.exe.config" Guid="PUT_GUID_HERE">
     <File Id="LayoutSwitcherWinSvc.exe.config" Name="LayoutSwitcherWinSvc.exe.config" Source="$(var.LayoutSwitcherWinSvc_TargetDir)LayoutSwitcherWinSvc.exe.config" />
  </Component>
  <Component Id="Transactions.dll" Guid="PUT_GUID_HERE">
    <File Id="Transactions.dll" Name="Transactions.dll" Source="$(var.LayoutSwitcherWinSvc_TargetDir)Transactions.dll" />
  </Component>
  <Component Id="Transactions.Cfg.dll" Guid="PUT_GUID_HERE">
    <File Id=" Transactions.Cfg.dll" Name="Transactions.Cfg.dll" Source="$(var.LayoutSwitcherWinSvc_TargetDir) Transactions.Cfg.dll" />
  </Component>

EDIT :1

Updated the source code after removing the service dependency, but still getting the same error.

EDIT :2

Removed the whitespaces, but still getting the same error.

EDIT :3

Verbose logs attached. Please download from the below link.
http://www.yourfilelink.com/get.php?fid=1432133

Best Answer

Can you try this piece of wix code? I cleaned it a little bit to remove some default values.

Unless you want to place the file with a different filename you don't need the Name attribute.

If you want your service to run as Local System then you need to set empty Account. If you want it to run as a specific user then you could set the properties on your command line SVCACCOUNT=someuser SVCPASSWORD="password", otherwise just skip them.

If Name and Id is the same then you can skip the Id.

I prefer to use variables for things that I use in multiple places to avoid typos, for example ServiceName that is used in ServiceInstall and ServiceControl I use:

<WixVariable Id="ServiceName" Value="LayoutSwitcher" />

<Component Id="PlcmLayoutSwitcherWinSvc.exe" Guid="PUT_GUID_HERE">
  <File Id="LayoutSwitcherWinSvc.exe" Source="$(var.LayoutSwitcherWinSvc_TargetDir)LayoutSwitcherWinSvc.exe" KeyPath="yes" />
  <ServiceInstall Name="!(wix.ServiceName)"
                  DisplayName="LayoutSwitcher"
                  Description="LayoutSwitcher"
                  ErrorControl="ignore"
                  Type="ownProcess" 
                  Vital="yes"
                  Start="auto"
                  Account="[SVCACCOUNT]"
                  Password="[SVCPASSWORD]" 
                  Interactive="no" />
  <ServiceControl Id="ServiceControl_!(wix.ServiceName)"
                  Name="!(wix.ServiceName)"
                  Start="install"
                  Stop="both"
                  Remove="uninstall"
                  Wait="yes" />
</Component>

The log you attached is incomplete, run the installer all the way through and attach the log only after you've closed the installer. IMO Debug log is not necessary.