0

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

Stein Åsmul
  • 34,628
  • 23
  • 78
  • 140
mbursill
  • 2,229
  • 1
  • 27
  • 39
  • There is no major upgrade element in that source, so it's not clear what upgrade you're doing and where it is sequenced. Doing the upgrade with a verbose log would help show what's going on. – PhilDW Oct 11 '17 at 16:46
  • FYI- I see a bunch of XML PDB and DLL files that shouldn't be included in your installer. System.*.dll are generally installed by the .NET framework. – Christopher Painter Oct 11 '17 at 23:12

2 Answers2

1

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.

Stein Åsmul
  • 34,628
  • 23
  • 78
  • 140
  • Appreciate the help. I'm a WiX novice so not surprised by the high error count. H drive is a data-only disk, not sure why it chose that. The attributes of the ServiceControl node are probably odd, I'm changing them to Start="install" Stop="uninstall" Remove="uninstall". Not sure how the versions on the DLL's are lower, I'm looking into that. Those are the files preventing the service from starting, so that's clearly the culprit. The state after the install is not good. The folders/files are removed, it appears uninstalled, but it lists with: Get-WmiObject -class Win32_Product – mbursill Oct 11 '17 at 22:50
  • OK, I would do a good cleanse of the system by uninstalling all stray versions of your application. Do you see it in add/remove programs? If not you might have a little case. You could try a fixit tool from Microsoft. [Check this answer](https://stackoverflow.com/questions/450027/uninstalling-an-msi-file-from-the-command-line-without-using-msiexec/1055933#1055933). The paragraph that starts with "if you have problems uninstalling altogether". Just to check if there is something stuck. – Stein Åsmul Oct 11 '17 at 22:56
  • You can enumerate all installed products directly via the MSI automation interface using this little script: https://stackoverflow.com/questions/28963089/how-to-find-out-which-products-are-installed-newer-product-are-already-install/28971679#28971679. It should be the definitive list of what is actually installed. I would do an ``msiexec /x {ProdGuid}`` (uninstall) for any stray installs you find via that script (if any). – Stein Åsmul Oct 11 '17 at 23:07
  • He's using well worn project templates and designers from IsWiX. It's very standard SI/SC and MajorUpgrade stuff. It does assume that DLL's and EXE's are properly versioned (Windows Installer pickyness) – Christopher Painter Oct 11 '17 at 23:11
1

Why do you say the service is started "before all the files have been installed"? It's not clear if you are guessing or there's some extra information you haven't posted. The problem certainly appears to be that the service failed to start, but again, why do you say that this is because files are missing?

I'll note again that the log you supplied is not the log of the source WiX you posted because that source has no major upgrade capability, and the posted source also has a service called "Agent" which is not the name of the service in the log. Since we are talking services here it'd not helpful when neither the source WiX or the service names match the log.

Having said that, and assuming that there are missing files, the most likely issue is that you've run into a Windows Installer bug where it decides not to uninstall a file and then discovers that this is an upgrade but removes it anyway. This post describes the issue and that you can try sequencing RemoveExistingProducts before CostInitialize to see if that corrects it"

WiX MSI upgrade disallows installation of some components

You should also check that you haven't got the similar issue reported here:

https://blogs.msdn.microsoft.com/astebner/2015/11/16/why-windows-installer-removes-files-during-a-major-upgrade-if-they-go-backwards-in-version-numbers/

where you're downgrading a file version during the upgrade.

PhilDW
  • 19,260
  • 1
  • 14
  • 23