Wix Toolset-升级且不覆盖配置文件

时间:2019-10-11 06:51:16

标签: wix

我有一个WPF应用程序,可以通过某些URL连接到某些Web服务。我进行了安装,它的工作原理像一个咒语,它甚至询问有关URL的信息并按照指示更改.config文件。现在,我想升级该应用程序,但保留.config文件不变。

我在网上尝试了一些解决方案,它不想升级,似乎每次都只能进行全新安装。

  <Package InstallerVersion="400" Compressed="yes" InstallScope="perMachine" Platform="x64" />
    <Icon Id="icon.ico" SourceFile="$(var.ProjectDir)Icon.ico" />
    <Property Id="ARPPRODUCTICON" Value="icon.ico" />
    <WixVariable Id="WixUIBannerBmp" Value="Images\installer_top-banner.bmp" />
    <WixVariable Id="WixUIDialogBmp" Value="Images\installer_background.bmp" />
    <WixVariable Id="WixUILicenseRtf" Value="$(var.ProjectDir)\license.rtf" />
    <Property Id="ARPURLINFOABOUT" Value="http://www.Company.com" />
  <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
    <Property Id="FULLURL" Value="http://demo.Company.com/WcfFullPortal.svc" Secure="yes" />
  <Property Id="AUTH" Value="0" Secure="yes" />
  <Property Id="AUTHVALUE" Value="$(var.httpValue)" Secure="yes" />
  <Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
  <Upgrade Id="1d96517a-8fc5-4150-b1cb-c3adf479a57d">
    <UpgradeVersion Minimum="1.0.0.0" Maximum="99.0.0.0" Property="PREVIOUSVERSIONSINSTALLED" IncludeMinimum="yes" IncludeMaximum="no" />
  </Upgrade>
  <UIRef Id="SetupDialogUI" />
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch MyApp" />
    <Property Id="WixShellExecTarget" Value="[#MyApp.UI.WPF.exe]" />
    <CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." AllowSameVersionUpgrades="yes" Schedule="afterInstallExecute" />
    <MediaTemplate EmbedCab="yes" />
    <!-- 32-bit / 64-bit variables -->
    <?if $(var.Platform) = x64 ?>
    <?define bitness = "(64 bit)" ?>
    <?define Win64 = "yes" ?>
    <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
    <?else?>
    <?define bitness = "(32 bit)" ?>
    <?define Win64 = "no" ?>
    <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
    <?endif?>
    <Condition Message="Minimum supported OS is Windows 7."><![CDATA[Installed OR (VersionNT >= 600)]]></Condition>
    <!-- 
<?if $(var.Platform) = x64 ?>
<Condition Message="You need to install the 32-bit version of this product on 32-bit Windows.">
  <![CDATA[VersionNT64]]>
</Condition>
<?endif?>
<?if $(var.Platform) = x86 ?>
<Condition Message="You need to install the 64-bit version of this product on 64-bit Windows.">
  <![CDATA[NOT VersionNT64]]>
</Condition>
<?endif?> -->


</Product>

...

                                                             

1 个答案:

答案 0 :(得分:1)

两种方法:

  1. 在安装程序中完成工作。 MSI不会在后续安装中保留(记住)属性。您必须将配置文件中的值重新获取到属性中,以便它可以再次显示在UI中,并在安装过程中重新应用。

http://robmensching.com/blog/posts/2010/5/2/the-wix-toolsets-remember-property-pattern/

  1. 将复杂性从安装程序移到应用程序中。设计应用程序,使其在首次运行时要求设置。使用app.config appSettings元素的file属性指定另一个包含替代设置的文件。让安装程序创建app.config而不是第二个文件。让应用程序将第一次运行时获得的设置保存到第二个文件中。安装程序对此一无所知,因此它将在以后的安装过程中永远不会触摸该文件。

https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/appsettings/appsettings-element-for-configuration

我是WiX专家,可以轻松处理方法1。对于WiX新手来说,这可能是一个挑战。我通常采用方法1时,它只有少数几个设置,并且该程序是非交互式的,例如Windows服务,或者说是Web应用程序,其中输入是池标识。否则,如果我将复杂性转移到他们能更好理解的代码上,我的客户就会更容易获得支持。