0

I am really very sorry for being redundant. I have checked a lot of other posts in this site itself and perhaps some other sites. I am not able to get Major Upgrade working without uninstalling & reinstalling of service. I am changing the Product Code and Version and the UpgradeFileComponent is the component that is part of the Upgrade. All the remaining are the same as in 1.0.0. I am doing a POC and hence would like to make only this small change (not as a patch, but as a major upgrade). Following is my Product.wxs. I am not including the markup for the other things like ServiceAccountDlg, Variables.wxi or en-us.wxl, since it may make it really long. Can anyone please help me? I have already tried WIX_UPGRADE_DETECTED, UPGRADINGPRODUCTCODE and so on, but not able to get it working. Everytime, the service is getting uninstalled and reinstalled. I am verifying this in the following way. Once the service starts, it creates a log file in ProgramData and keeps appending it to every 5 seconds. During uninstallation of the MSI, I am deleting this log file and its folder. After the service gets reinstalled and restarts, the log file gets created again. With this I am able to figure out that the service is getting reinstalled always with the major upgrade. I only want the new file to be deployed without reinstalling the service or any other component being uninstalled. I have heard from some people that the toolset checks for changed files and reinstalls them only if there is a change. But this doesn't seem to be the case. I have tried using the Schedule attribute with various values also, but no luck. Any help will be really great. I have been trying this for so many days without any luck. Please let me know if any more info is required from me.

<?xml version="1.0" encoding="UTF-8"?>
<?include Variables.wxi ?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>
  <Product Id="$(var.ProductCode)" Name="$(var.ProductName)" Language="!(loc.LANG)" Version="$(var.ProductVersion)" Manufacturer=" MyCompany" UpgradeCode="$(var.UpgradeCode)">

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

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

    <!--<Upgrade Id="$(var.UpgradeCode)">
      <UpgradeVersion OnlyDetect="yes" Minimum="1.0.0" Maximum="2.0.0" IncludeMinimum="yes" IncludeMaximum="yes" Property="NEWERFOUND"   />
    </Upgrade>-->

    <InstallExecuteSequence>
      <!--<RemoveExistingProducts After="InstallExecute" />
      <DeleteServices>NOT UPGRADINGPRODUCTCODE</DeleteServices>-->
      <!--<InstallServices>NOT UPGRADINGPRODUCTCODE,NOT WIX_UPGRADE_DETECTED</InstallServices>-->
      <DeleteServices>NOT UPGRADINGPRODUCTCODE</DeleteServices>
    </InstallExecuteSequence>

    <Condition Message='This application only runs on Windows 7 or higher OS versions.'>
      <![CDATA[Installed OR (VersionNT64 >= 601)]]>
    </Condition>

    <MediaTemplate />

    <Property Id="MSIFASTINSTALL" Value="1"/>
    <Property Id="MsiLogging" Value="v" />
    <Property Id="MSIENFORCEUPGRADECOMPONENTRULES" Value="1" />
    <Property Id="INSTALLDIR">
      <RegistrySearch Id='MyCompanyMSISampleRegistry' Type='raw' Root='HKLM' Key='SOFTWARE\MyCompany\CustomApp' Name='INSTALLDIR' Win64='yes' />
    </Property>

    <WixVariable Id="WixUILicenseRtf" Value="License.rtf" />
    <Feature Id='Complete' Title='Foobar 1.0' Description='The complete package.'
    Display='expand' Level='1' ConfigurableDirectory='INSTALLDIR' AllowAdvertise='no' InstallDefault='local' Absent='disallow'>

      <Feature Id="FileFeature" Title="File Feature" Level="1" AllowAdvertise='no' InstallDefault='local' Absent='disallow' Display='expand'>
        <ComponentRef Id="FileComponent"/>
        <ComponentRef Id="UpgradeFileComponent"/>
      </Feature>
      <Feature Id="ServiceFeature" Title="Service Feature" Level="1" AllowAdvertise='no' InstallDefault='local' Absent='disallow' Display='expand'>
        <ComponentRef Id="ServiceComponent"/>
        <ComponentRef Id="deleteFolder"/>
      </Feature>
      <Feature Id="RegistryFeature" Title="Registry Feature" Level="1" AllowAdvertise='no' InstallDefault='local' Absent='disallow' Display='expand'>
        <ComponentRef Id="RegistryComponent"/>
      </Feature>           
      <Feature Id='Documentation' Title='Description' Description='The instruction manual.' Level='2' AllowAdvertise='no' InstallDefault='followParent' Absent='disallow'>
        <ComponentRef Id='Manual' />
      </Feature>

    </Feature>
    <!--<UIRef Id="WixUI_Mondo"/>
    <UIRef Id="WixUI_ErrorProgressText" />-->

    <UI Id="MyWixUI_Mondo">
      <UIRef Id="WixUI_Mondo" />

      <DialogRef Id="ServiceAccountDlg" />

      <Publish Dialog="LicenseAgreementDlg" Control="Next" Event="NewDialog" Value="ServiceAccountDlg" Order="2">LicenseAccepted = "1"</Publish>
      <Publish Dialog="SetupTypeDlg" Control="Back" Event="NewDialog" Value="ServiceAccountDlg">1</Publish>
    </UI>
    <UIRef Id="WixUI_ErrorProgressText" />

    <Icon Id="MyCompanyBanner.ico" SourceFile="Binary\MyCompanyBanner.ico" />

  </Product>

  <Fragment>
    <Component Id='Manual' Guid='7470A2CD-B07C-4AB4-9152-8C6AA53FA0F7' Directory='INSTALLDIR'>
      <File Id='Manual' Name='Manual.pdf' DiskId='1' Source='1.0.0\Manual.pdf' KeyPath='yes'>
        <Shortcut Id="startmenuManual" Directory="DesktopFolder" Name="Instruction Manual" Advertise="yes" />
      </File>
    </Component>
  </Fragment>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLDIR" Name="$(var.InstallFolderName)" />
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop" />
      <Directory Id="CommonAppDataFolder">
        <Directory Id="MyCompanyTestInstallerLogs" Name="MyCompanyTestInstallerLogs">
          <Component Id="deleteFolder" Guid="323549D2-90B7-4D5D-8A36-EEA0ACCCC35E">
            <RemoveFile Id="deleteServiceFile" Name="MyCompanyTestWinSvcLog.txt" On="both" Directory="MyCompanyTestInstallerLogs"/>
            <RemoveFolder Directory="MyCompanyTestInstallerLogs" Id="MyCompanyTestInstallerLogs" On="both"/>
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </Fragment>

  <Fragment>
    <Component Id="FileComponent" Directory="INSTALLDIR" Guid="F143BE3C-48D6-4138-B4E6-5CF44773CBA5" >      
      <File Id="SampleTextFile.txt" Name="Sample.txt" Source="$(var.Version)\Sample.txt" KeyPath="yes">
        <Shortcut Id="startmenuSampleText" Directory="DesktopFolder" Name="MyCompany MSI Sample" WorkingDirectory='INSTALLDIR' Icon='MyCompanyBanner.ico' Advertise='yes' />
      </File>
    </Component>
  </Fragment>

  <Fragment>
    <Component Id="UpgradeFileComponent" Directory="INSTALLDIR" Guid="4582597C-2CE0-451E-8B89-83BA4ABCE464">    
      <File Id="SampleXMLFile.xml" Name="Sample.xml" Source="$(var.Version)\Sample.xml" KeyPath="yes" />
    </Component>
  </Fragment>

  <Fragment>
    <Component Id='ServiceComponent' Directory="INSTALLDIR" Guid="AEA0E53F-3D70-4010-8592-9A01FE49344D">
      <util:User Domain="[DOMAIN]" Id="svcUser" Name="[USER_NAME]" Password="[PASSWORD]" LogonAsService="yes" CreateUser="no"/>
      <File Id='MyCompanyTestWinSvc' Name='MyCompanyTestWinSvc.exe' Source='Binary\MyCompanyTestWinSvc.exe' KeyPath='yes' />
      <ServiceInstall Id="installMyCompanyTestWinSvc" Name="MyCompanyTestWinSvc" DisplayName="MyCompany Install Test Windows Service" Start="auto" ErrorControl="normal" Type="ownProcess" Account="[DOMAIN]\[USER_NAME]" Password="[PASSWORD]" />
      <ServiceControl Id="sc_MyCompanyTestWinSvc" Name="MyCompanyTestWinSvc" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
      <ServiceControl Id="stopAndStartIIS" Name="IISADMIN" Start="uninstall" Stop="install" Wait="yes" />
      <ServiceControl Id="stopAndStartSQL" Name="MSSQLSERVER" Start="uninstall" Stop="install" Wait="yes" />
    </Component>
  </Fragment>

  <Fragment>
    <Component Id="RegistryComponent" Directory="INSTALLDIR" Guid="8D8D93A4-09F5-4511-B291-720A7BC70529">
      <RegistryValue Root='HKCU' Key='Software\[Manufacturer]\[ProductName]' Type='string' Value='' KeyPath='yes' />
    </Component>
  </Fragment>

</Wix>
PhilDW
  • 20,260
  • 1
  • 18
  • 28
Ven
  • 235
  • 4
  • 12
  • Possible duplicate of [WiX Upgrade without uninstallation of existing version](https://stackoverflow.com/questions/47307640/wix-upgrade-without-uninstallation-of-existing-version) – Michael Urman Nov 20 '17 at 13:54

2 Answers2

1

Your MajorUpgrade does not specify where it is scheduled. As the docs say, the default is after InstallValidate and "This scheduling removes the installed product entirely before installing the upgrade product. " So your major upgrade will uninstall the older product completely, deleting the service, and then install your upgrade.

So you should start by having your major upgrade scheduled afterInstallExecute, because this will behave like an update on top of the existing installed product and the reference counting should minimize disruption to your service. This means that you must follow component rules, and increment the file versions of versioned files that need replacing.

Having said that, an upgrade is always an uninstall of the older product, so the ServiceControl in that older version will run, and Remove="both" might be the problem, deleting the service during the upgrade. So the original WiX ServiceControl matters.

Also, if the component rules haven't been followed an upgrade afterInstallValidate will work fine because it uninstalls everything then installs the new product. But if the component rules have not been followed in an upgrade afterInstallExecute the service component may be getting uninstalled (because of differing component ids), and there may well be other effects of not following the rules.

And to make it clear, you do not need a condition on delete services in your new install. I would start just by sequencing the major upgrade in a better place. Also, UPGRADINGPRODUCTCODE as a condition in your new upgrade has absolutely no effect. This property is set in the older product if it is being uninstalled with an upgrade. If you want to use this property it should be in the original product that is already installed, so if it's shipped and installed it is too late to alter that code now (without a patch and so on).

A more verbose MSI log would show more detail about what is happening and in what order, specify the string as voicewarmup.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
  • As I mentioned earlier, I had tried with the Schedule attribute and all its possible values, but no luck. Please look at my Product.wxs file and let me know if I have violated the component rules. Also, I couldn't find a concrete blog / forum / article which defines the component rules in a clear cut way. Although Rob Mensching has written an article, I couldn't figure out much from it. – Ven Nov 21 '17 at 04:56
  • Component rules relate to all the component Ids of your files, registry entries, and the product's wxs file does not show that. It is still true that the default schedule of your upgrade afterInstallValidate is the wrong place, so I'd move on to aferInstallExecute and me more specific about the result, and get a complete verbose, and keep in mind that if the uninstall of the older product is deleting the service there's nothing you can do about that in your upgrade MSI. – PhilDW Nov 21 '17 at 20:34
  • Thanks a lot for your response Phil. So, do you mean to say that my components are not as per the rules? If so, can you please help me correct them. Also, as I mentioned earlier, I had tried Schedule="afterInstallExecute" and "afterInstallFinalize", but nothing worked. The log file is clearly having entries for Delete Service actions. – Ven Nov 22 '17 at 07:14
  • I didn't say you were breaking the component rules - nobody can tell from the product.wxs file. In an upgrade there will be at least 4 DeleteServices actions, some of which don't do anything, so you will see them because they are in the execute sequences of the upgrade install and the old product's uninstall. Their presence doesn't automatically mean deletion of a service. I recommend posting a new question with the upgrade after InstallExecute and have that verbose log available. – PhilDW Nov 22 '17 at 18:30
0

I added this to my <InstallExecuteSequence>

<!-- http://stackoverflow.com/questions/15965539/how-to-only-stop-and-not-uninstall-windows-services-when-major-upgrade-in-wix don't change service config on upgrade -->
<DeleteServices>NOT UPGRADINGPRODUCTCODE</DeleteServices>            
<InstallServices>NOT WIX_UPGRADE_DETECTED</InstallServices>

Seemed to work for me but I don't use this anymore due to changes in the product. You have to be sure you won't be changing the configuration of the service between versions since when you do change the configuration you do need to uninstall and install the services during the upgrade.

Services only get deleted on real unininstall (Rob [answerer of commented question] notes you don't need to condition around the Remove state since the install/uninstall state of the services is noted in the components)

And we only install the services on the first install.

Brian Sutherland
  • 4,698
  • 14
  • 16
  • 1
    It is not working for me, though. In any case, it is deleting / uninstalling the service, even though there are no changes in the service exe. – Ven Nov 21 '17 at 03:37