[wix-users] Finding XML File to update after installing

Phill Hogland phill.hogland at rimage.com
Mon Sep 14 10:09:48 PDT 2015


I use heat  (via a HeatDirectory target, but used to use heat.exe directly) and for this situation I pass in a transform which strips the exe and the config file from the harvested components.  I then manually author those files.  I know that it is possible to use a transform to add the authoring right into the harvested wxs, but this approach was simpler for me to implement across a number of projects with config files.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:wix='http://schemas.microsoft.com/wix/2006/wi'
    xmlns:fire='http://schemas.microsoft.com/wix/FirewallExtension'
    xmlns='http://schemas.microsoft.com/wix/2006/wi'
    exclude-result-prefixes='wix'
    >

  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="utf-8"/>
  <xsl:strip-space  elements="*"/>

  <xsl:template match="@*|*">
    <xsl:copy>
      <xsl:apply-templates select="@*" />
      <xsl:apply-templates select="*" />
    </xsl:copy>
  </xsl:template>

  <xsl:key name="MyApp.exe-search" match="wix:Component[contains(wix:File/@Source, 'MyApp.exe')]" use="@Id" />
  <xsl:template match="wix:Component[key('MyApp.exe -search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('MyApp.exe -search', @Id)]" />

  <xsl:key name="MyApp.exe.config-search" match="wix:Component[contains(wix:File/@Source, 'MyApp.exe.config')]" use="@Id" />
  <xsl:template match="wix:Component[key('MyApp.exe.config -search', @Id)]" />
  <xsl:template match="wix:ComponentRef[key('MyApp.exe.config -search', @Id)]" />
</xsl:stylesheet>

      <Component Id="'MyApp.exe.config'" >
        <File Id="'MyApp.exe.config'" KeyPath="yes" Source="!(bindpath.STATIC_MyApp)\ MyApp.exe.config" />
        <util:XmlConfig Id='MyApp.exe.config'_Parameter'
                  File='[#'MyApp.exe.config']'
                  Action='create'
                  Node='value'
                  ElementPath="//configuration/appSettings/add[\[]@key='Parameter'[\]]"
                  Name="value"
                  Value="[MYPROPERTY]"
                  On='install'
                  PreserveModifiedDate='yes'
                  VerifyPath="//configuration/appSettings/add[\[]@key='Parameter'[\]]/"/>
......


-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Brian Enderle
Sent: Monday, September 14, 2015 11:34 AM
To: WiX Users <wix-users at lists.wixtoolset.org>
Subject: [wix-users] Finding XML File to update after installing

I am installing a Web.Config file that I would like to modify with values obtained during the installation process.

Originally I was manually identifying the files to install like so:

    <ComponentGroup Id="ProductComponents" Directory="INSTALL_FOLDER">
      <Component Id="WebConfig" Win64="yes">
        <File Id="WebConfig"
              Source="$(var.MyProduct.TargetDir)..\Web.config"
              Vital="yes"
              KeyPath="yes"/>
      </Component>
    </ComponentGroup>

I was then updating the XML file like so (which worked correctly):

    <Component Id="UpdateWebConfig"
Guid="{43C4881A-96ED-4361-A5F8-D8B37EEBCFB3}" Directory="INSTALL_FOLDER">
      <CreateFolder />

      <!-- START - Value comes from AcctInfoDlg.wxs -->
      <util:XmlFile Id="UpdateSiteName"
                    Action="setValue"
                    File="[#WEB_CONFIG]"

ElementPath="//configuration/appSettings/add[\[]@key='siteName'[\]]/@value"
                    Value="[SITE_NAME]"
                    Sequence="1" />


I have since switched to using Heat to extract all the files contained in the $(var.MyProduct.TargetDir) and am no longer able to modify the XML file.  I know I can no longer use the [#WEB_CONFIG] property that originally was assigned in the <Component> tag.

The entry for the Web.Config file once extracted via heat looks like:

            <Component Id="cmp67BE95547033126CD732423EE8405F52" Guid="*">
                <File Id="filD7C0321AB7E9E3711DC847528EB85A24"
KeyPath="yes" Source="$(var.PublishedDir)\Web.config" />
            </Component>



I tried adding a property to the installation that would return the Web.Config file properties like so:

    <Property Id="WEB_CONFIG">
      <DirectorySearch Id="TOOL_PATH" Path="[INSTALL_FOLDER]" Depth="0">
        <FileSearch Id="WEB_CONFIG_FILE" Name="Web.Config" />
      </DirectorySearch>
    </Property>

and then update the Web.Config file, using this property as the location of the file to update.  However, when I run my installer I get the following error in the log file:

\bin\,  Size: 42656
MSI (s) (B0:E8) [12:20:15:661]: Executing op: CacheSizeFlush(,) MSI (s) (B0:E8) [12:20:15:661]: Executing op:
ActionStart(Name=ExecXmlConfig,,)
Action 12:20:15: ExecXmlConfig.
MSI (s) (B0:E8) [12:20:15:661]: Executing op:
CustomActionSchedule(Action=ExecXmlConfig,ActionType=3073,Source=BinaryData,Target=ExecXmlConfig,CustomActionData=2€€3€0€//configuration/appSettings/add[@key='siteName']/€€€asdfg€0)
MSI (s) (B0:18) [12:20:15:661]: Invoking remote custom action. DLL:
C:\WINDOWS\Installer\MSIEE2A.tmp, Entrypoint: ExecXmlConfig MSI (s) (B0:98) [12:20:15:661]: Generating random cookie.
MSI (s) (B0:98) [12:20:15:677]: Created Custom Action Server with PID 10676 (0x29B4).
MSI (s) (B0:FC) [12:20:15:708]: Running as a service.
MSI (s) (B0:FC) [12:20:15:708]: Hello, I'm your 32bit Elevated Non-remapped custom action server.
ExecXmlConfig:  Error 0x8007006e: failed to load XML file:
Error 25541. Failed to open XML file , system error: -2147024786

How can I reference a file I just installed in order to update it?



Brian

If you can't explain it simply, you don't understand it well enough.  - Albert Einstein

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant http://www.firegiant.com/


More information about the wix-users mailing list