Search code examples
wixwindows-installeriswix

WiX starting service before all files are copied


I have a merge module which defines all the components/resources, plus installs and starts a service.

This builds an installer which works during a clean install. When upgrading from a previous version, it attempts to start the service before all the files have been copied (the service depends on those files). How do I get WiX to start the service after the files have been copied?

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?define ComponentRules="OneToOne"?>
  <!-- SourceDir instructs IsWiX the location of the directory that contains files for this merge module -->
  <?define SourceDir="..\Deploy"?>
  <Module Id="AgentMM" Language="1033" Version="1.2.1">
    <Package Id="*" Manufacturer="Example Inc" InstallerVersion="500" InstallPrivileges="elevated" InstallScope="perMachine" />
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="CommonAppDataFolder" Name="CommonAppData">
        <Directory Id="owdF4A3A065B05943EB31D4A22FB4A609B2" Name=" ">
          <Directory Id="owd054D805088608C669D54B91D1372FB13" Name="agent">
            <Component Id="owc054D805088608C669D54B91D1372FB13" Guid="*">
              <CreateFolder />
            </Component>
          </Directory>
        </Directory>
      </Directory>
      <Directory Id="MergeRedirectFolder">
        <Component Id="owcE4483ACA0E06F6931349C52F4DE32B04" Guid="*">
          <File Id="owfE4483ACA0E06F6931349C52F4DE32B04" Source="$(var.SourceDir)\Agent.exe" KeyPath="yes" />
          <ServiceInstall Id="si1F414070C0DF7193A1D990B85A956139" Name="Agent" DisplayName="Agent" Description="Reports on system health" ErrorControl="normal" Start="auto" Type="ownProcess" Interactive="no" />
          <ServiceControl Id="sc1F414070C0DF7193A1D990B85A956139" Name="Agent" Start="install" Stop="both" Remove="both" Wait="yes" />
        </Component>
        <Component Id="owcB927FFAE9DA1BF9B833D1BB6615B7D1F" Guid="*">
          <File Id="owfB927FFAE9DA1BF9B833D1BB6615B7D1F" Source="$(var.SourceDir)\Cassia.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc4068B8346D37AA0AFB49DF9E39B8C148" Guid="*">
          <File Id="owf4068B8346D37AA0AFB49DF9E39B8C148" Source="$(var.SourceDir)\Cassia.xml" KeyPath="yes" />
        </Component>
        <Component Id="owc52F75CE3A69F808CE9B7861F5FF157E7" Guid="*">
          <File Id="owf52F75CE3A69F808CE9B7861F5FF157E7" Source="$(var.SourceDir)\Agent.exe.config" KeyPath="yes" />
        </Component>
        <Component Id="owc983DF61596DB6BCFA851E8953561E349" Guid="*">
          <File Id="owf983DF61596DB6BCFA851E8953561E349" Source="$(var.SourceDir)\Agent.pdb" KeyPath="yes" />
        </Component>
        <Component Id="owc2BF30E4776996DDD68B184F69F7D1E00" Guid="*">
          <File Id="owf2BF30E4776996DDD68B184F69F7D1E00" Source="$(var.SourceDir)\Utilities.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcE10E1E5CADEF47AEB294ED17810D9F5D" Guid="*">
          <File Id="owfE10E1E5CADEF47AEB294ED17810D9F5D" Source="$(var.SourceDir)\Utilities.pdb" KeyPath="yes" />
        </Component>
        <Component Id="owcADE9A457248959D397C6B092C7CCF78B" Guid="*">
          <File Id="owfADE9A457248959D397C6B092C7CCF78B" Source="$(var.SourceDir)\Microsoft.Win32.Primitives.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc3FC8434C1A84605AEEBC6A100CA2F3E1" Guid="*">
          <File Id="owf3FC8434C1A84605AEEBC6A100CA2F3E1" Source="$(var.SourceDir)\Newtonsoft.Json.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcDE8FDCCF922CA433A075036DF5C1BE38" Guid="*">
          <File Id="owfDE8FDCCF922CA433A075036DF5C1BE38" Source="$(var.SourceDir)\Newtonsoft.Json.xml" KeyPath="yes" />
        </Component>
        <Component Id="owcBC6AFA6932E46F7635B750194F2DFE30" Guid="*">
          <File Id="owfBC6AFA6932E46F7635B750194F2DFE30" Source="$(var.SourceDir)\Nito.AsyncEx.Context.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcB0247DD3838FC1DDFA9BBA29DDE5A2DB" Guid="*">
          <File Id="owfB0247DD3838FC1DDFA9BBA29DDE5A2DB" Source="$(var.SourceDir)\Nito.AsyncEx.Context.xml" KeyPath="yes" />
        </Component>
        <Component Id="owc80E1432E52AF192AE3A458644EFA81C1" Guid="*">
          <File Id="owf80E1432E52AF192AE3A458644EFA81C1" Source="$(var.SourceDir)\Nito.AsyncEx.Tasks.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc956AF9D61B4B96E805D3B6990EC17870" Guid="*">
          <File Id="owf956AF9D61B4B96E805D3B6990EC17870" Source="$(var.SourceDir)\Nito.AsyncEx.Tasks.xml" KeyPath="yes" />
        </Component>
        <Component Id="owc9797AB99B9AB073F5FAFAE13A51ECE35" Guid="*">
          <File Id="owf9797AB99B9AB073F5FAFAE13A51ECE35" Source="$(var.SourceDir)\Nito.Disposables.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc33EA8A2869C77F471EBAD2451B964902" Guid="*">
          <File Id="owf33EA8A2869C77F471EBAD2451B964902" Source="$(var.SourceDir)\Nito.Disposables.xml" KeyPath="yes" />
        </Component>
        <Component Id="owc25FBE4153F32A5634B0ADA8A6954CC89" Guid="*">
          <File Id="owf25FBE4153F32A5634B0ADA8A6954CC89" Source="$(var.SourceDir)\System.AppContext.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc2F5D24BF1EA2D036DA793146E86BDF87" Guid="*">
          <File Id="owf2F5D24BF1EA2D036DA793146E86BDF87" Source="$(var.SourceDir)\System.Collections.Immutable.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc2BE2107F9B51B79FDB1B19EA807C9C44" Guid="*">
          <File Id="owf2BE2107F9B51B79FDB1B19EA807C9C44" Source="$(var.SourceDir)\System.Collections.Immutable.xml" KeyPath="yes" />
        </Component>
        <Component Id="owcA90D9D10E6DAB6E67011458672887086" Guid="*">
          <File Id="owfA90D9D10E6DAB6E67011458672887086" Source="$(var.SourceDir)\System.Console.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcBC11F886BA2AB9469783C04435BCA0B9" Guid="*">
          <File Id="owfBC11F886BA2AB9469783C04435BCA0B9" Source="$(var.SourceDir)\System.Diagnostics.DiagnosticSource.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc918BEF5091074ABD7E2C05293EDBFE17" Guid="*">
          <File Id="owf918BEF5091074ABD7E2C05293EDBFE17" Source="$(var.SourceDir)\System.Diagnostics.DiagnosticSource.xml" KeyPath="yes" />
        </Component>
        <Component Id="owc38B2B9FCCE93A2C7D2E931C05D695098" Guid="*">
          <File Id="owf38B2B9FCCE93A2C7D2E931C05D695098" Source="$(var.SourceDir)\System.Diagnostics.Tracing.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcB1B1D5CD5E0525947D05C2530DDA9E96" Guid="*">
          <File Id="owfB1B1D5CD5E0525947D05C2530DDA9E96" Source="$(var.SourceDir)\System.Globalization.Calendars.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc5AC6699E38D4EE124CC260C1E19F025A" Guid="">
          <File Id="owf5AC6699E38D4EE124CC260C1E19F025A" Source="$(var.SourceDir)\System.IO.Compression.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc87D8454A10E8D4063130BA0D60AAE450" Guid="*">
          <File Id="owf87D8454A10E8D4063130BA0D60AAE450" Source="$(var.SourceDir)\System.IO.Compression.ZipFile.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc7600C49A56A3819C607969AD7D76A1D1" Guid="*">
          <File Id="owf7600C49A56A3819C607969AD7D76A1D1" Source="$(var.SourceDir)\System.IO.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc6A348A5B38822B45BE742FD5B11ACF09" Guid="*">
          <File Id="owf6A348A5B38822B45BE742FD5B11ACF09" Source="$(var.SourceDir)\System.IO.FileSystem.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc6AF351692769A11F3108B81F1F6AC695" Guid="*">
          <File Id="owf6AF351692769A11F3108B81F1F6AC695" Source="$(var.SourceDir)\System.IO.FileSystem.Primitives.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc14A5BB088914D21BDD2FBEE1395FD78B" Guid="*">
          <File Id="owf14A5BB088914D21BDD2FBEE1395FD78B" Source="$(var.SourceDir)\System.Linq.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc06E33481927840239152432A87297CC9" Guid="*">
          <File Id="owf06E33481927840239152432A87297CC9" Source="$(var.SourceDir)\System.Linq.Expressions.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcB279CD308898A9D5EFCE20D942FB230A" Guid="*">
          <File Id="owfB279CD308898A9D5EFCE20D942FB230A" Source="$(var.SourceDir)\System.Net.Http.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcE7C4094F57B0A8D61E66E0978388F384" Guid="*">
          <File Id="owfE7C4094F57B0A8D61E66E0978388F384" Source="$(var.SourceDir)\System.Net.Http.Formatting.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcAB556DAB8513CFEB9A95F8187FBB7D96" Guid="*">
          <File Id="owfAB556DAB8513CFEB9A95F8187FBB7D96" Source="$(var.SourceDir)\System.Net.Http.Formatting.xml" KeyPath="yes" />
        </Component>
        <Component Id="owcC356900D1A9E2893A31E87C428F0E41B" Guid="*">
          <File Id="owfC356900D1A9E2893A31E87C428F0E41B" Source="$(var.SourceDir)\System.Net.Sockets.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc7A6EE41CC1504CC124313BD05EDA4F44" Guid="*">
          <File Id="owf7A6EE41CC1504CC124313BD05EDA4F44" Source="$(var.SourceDir)\System.Reflection.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcCD2580ECA1FA1A3513916545D2F2BFA5" Guid="*">
          <File Id="owfCD2580ECA1FA1A3513916545D2F2BFA5" Source="$(var.SourceDir)\System.Runtime.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcB0183318DD63CCAB717750C767DC21D7" Guid="*">
          <File Id="owfB0183318DD63CCAB717750C767DC21D7" Source="$(var.SourceDir)\System.Runtime.Extensions.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc456C772F6BA4F8274FFF4540362C5A62" Guid="*">
          <File Id="owf456C772F6BA4F8274FFF4540362C5A62" Source="$(var.SourceDir)\System.Runtime.InteropServices.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc142B759C8549F55E22EAD18CF214B77E" Guid="*">
          <File Id="owf142B759C8549F55E22EAD18CF214B77E" Source="$(var.SourceDir)\System.Runtime.InteropServices.RuntimeInformation.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcD6CB46E32249D9DFE253203C9E68622F" Guid="*">
          <File Id="owfD6CB46E32249D9DFE253203C9E68622F" Source="$(var.SourceDir)\System.Security.Cryptography.Algorithms.dll" KeyPath="yes" />
        </Component>
        <Component Id="owcF620F5D5E0DED6F51741DE9E09BAA10C" Guid="*">
          <File Id="owfF620F5D5E0DED6F51741DE9E09BAA10C" Source="$(var.SourceDir)\System.Security.Cryptography.Encoding.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc0F0B6DF93E003C893A5E5E253BAF6C85" Guid="*">
          <File Id="owf0F0B6DF93E003C893A5E5E253BAF6C85" Source="$(var.SourceDir)\System.Security.Cryptography.Primitives.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc328828932DA40CAED6EC4EA121F7534D" Guid="*">
          <File Id="owf328828932DA40CAED6EC4EA121F7534D" Source="$(var.SourceDir)\System.Security.Cryptography.X509Certificates.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc50D709F95681A7937E1395ED21E4DE32" Guid="*">
          <File Id="owf50D709F95681A7937E1395ED21E4DE32" Source="$(var.SourceDir)\System.Text.RegularExpressions.dll" KeyPath="yes" />
        </Component>
        <Component Id="owc1EC9EF9564C76F0DA10AA382F306146E" Guid="*">
          <File Id="owf1EC9EF9564C76F0DA10AA382F306146E" Source="$(var.SourceDir)\System.Xml.ReaderWriter.dll" KeyPath="yes" />
        </Component>
      </Directory>
    </Directory>
    <ComponentGroupRef Id="Custom" />
  </Module>
</Wix>

Upgrade Log: https://pastebin.com/cDUFT98Q


Solution

  • I am winging it - I am not set up to test this properly at the moment, but here goes:

    Some Questions

    • There are many errors in your log file. What is the actual installation state at the end of that log file? Do you have two entries in add/remove programs for the same application / MSI install? It sort of looks like a failed major upgrade in the log file, but it is a little hard to tell. It looks like at least one of the installs rolls back, perhaps both. What is the end state on your machine?
    • Your TARGETDIR and ROOTDRIVE are set to H:. What is that about? What is on your H: drive? Your IIS installation? It looks like C:\ is your system folder.
    • Why have you set the service to uninstall on both install and uninstall? What does the ServiceControl and ServiceInstall tables look like in your compiled MSI file? (Open with Orca or equivalent to check - great if you report the values. Particularly ServiceInstall:ServiceType, and ServiceControl:Event). It has been a while since I installed services, but as I recall only a few options really make sense. I think I always used: create on install, stop and start on install, and stop and delete on uninstall. In other words: try without the delete on install.
    • The following files will never install: Nito.AsyncEx.Tasks.xml and Nito.AsyncEx.Context.dll due to this log message:

    MSI (s) (BC:D4) [11:46:53:020]: Disallowing installation of component: {6EA4EDA3-FBF8-8B13-1DAA-342C5D7EDCB5} since the same component with higher versioned keyfile exists MSI (s) (BC:D4) [11:46:53:022]: Disallowing installation of component: {7B9CD5B0-C538-77AE-E4D9-87B4A74C6207} since the same component with higher versioned keyfile exists

    • You should fix the version numbers for the dll so the upgraded MSI installs the right version. Could these missing file versions prevent your service from starting?

    Log File Checking

    I am not sure what to recommend, except help you read the log file properly as you experiment. I did skim your log, and there are several oddities in there - several failed actions. Whenever you make a log file you should always first search for "value 3" as explained by Rob Mensching (WiX creator).

    So search for "value 3". Study the errors, and then check these links for interpreting the errors returned:

    This isn't a real answer I suppose, but some links to get you going. Give it a go and let us know what happens so we can "evolve" the answer if there is more info.