Gergo Szucs
Gergo Szucs

Reputation: 105

WIX Writing user data into config file

I would like to ask a WiX installer question. I created a working installer that does many things already. I still need to ask the user for some specific information (the GUI is already done), and write it into a config file.

From this snippet, I think I could use the INSTALLFOLDER global variable.

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="IISROOT" Name='WebDir'>
    <Directory Id="INSTALLFOLDER" Name="IVRDesigner">
    </Directory>
  </Directory>
</Directory>

This is the part, when I want to use that. This code is taken from a tutorial, should work well, if the source tag is filled properly. The ..\src\Web.config is just a dummy, so the code can compile. The default installed path for the web.config file will be C:\inetpub\wwwroot\myfolder, but the user can change this during the installation.

The question is: how could I use the global variable here, or what kind of solution, do you recommend?

Thanks in advance.

<Component Id="ConfigureWebConfig" Guid="*">
    <File Id="Web.config" Name="MyConfigfile" Vital="yes" KeyPath="yes" 
          Source="..\src\Web.config" />
    <util:XmlFile Id="AppConfigSetConnStr" Action="setValue" 
         Permanent="yes" File="[#Web.config]"
         ElementPath="/configuration/connectionStrings/add[\[]@name='GeoIVRDesignerEntities'[\]]" Name="connectionString"
         Value="data source=[DBSERVER];" />
  </Component>

Upvotes: 3

Views: 2400

Answers (1)

CheGueVerra
CheGueVerra

Reputation: 7963

Under the Product tag I would add the properties that I want to be able to change in the config file like this:

<Property Id="BUILDRAN" Value="INSTALLER"/>
<Property Id="EMAIL_RECEIPIANT" Value="[email protected]" />

Create the Fragment for the Directory Structure

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir" >
      <Directory Id="BasicDir" Name="Dev_Home">
        <Directory Id="BasicDirSuite" Name="TEST">
          <Directory Id="INSTALLFOLDER" Name="DesignPatterns" />
        </Directory>
      </Directory>
    </Directory>
  </Fragment>

Declare another Fragment for the transformation of the config file

<util:XmlFile Id="AppConfigSetBuildRan" Action="setValue" Permanent="yes" File="[#App.config]"
     ElementPath="/configuration/applicationSettings/MyApp.Properties.Settings/setting[\[]@name='BuildRan'[\]]/value"
     Value="[BUILDRAN]" />

<util:XmlFile Id="AppConfigSetEmail" Action="setValue" Permanent="yes" File="[#App.config]"
    ElementPath="/configuration/applicationSettings/MyApp.Properties.Settings/setting[\[]@name='TestValue'[\]]/value"
    Value="[EMAIL_RECEIPIANT]" />

If you want you can create your own custom dialog to let the End user enter values for the properties [BUILDRAN] && [EMAIL_RECEIPIANT], or you could use the command line and set the properties with parameters

msiexec /i My.msi BUILDRAN=SuperDebug [email protected]

Upvotes: 4

Related Questions