user4929740
user4929740

Reputation:

Wixtoolset, specifying source to a file based on where the installer is

How do I specify the source of a file based on where the installer I am running is located. Say for example that I want to place a few files from the folder of the installer(that is for instance located on the desktop or in downloaded files) into a specified path in C/programfiles.

  <ComponentGroup Id="ProgramFilesFolder_files" Directory="INSTALLFOLDER">
  <Component Id="Program.exe" Guid="d0c868d9-4d5b-41f0-9ce8-d655ac80ee7c">
    <File Id="Program.exe" Name="Program.exe" Source="???" />

How do I set the source property?

Have i understood it right that I am supposed to set the source to:

Source="..\Program.exe"

Does this refer to where the MSI file is run from. If I for example put my installer file along with the files I need the source for. Will I be able to use the code above as a relative path that changes when I move the installer. So I can run the installer from elsewhere, with the only requierment that the installer is in the same folder as the files I want to program the source for?

Upvotes: 0

Views: 2117

Answers (1)

Christopher Painter
Christopher Painter

Reputation: 55581

I have an open source project that makes authoring WiX installers easier. One of it's features is relative file paths. You can read about it here.

https://github.com/iswix-llc/iswix-tutorials

Essentially the project templates use an XPI called SourceDir to create an abstraction for where to find the source files. This is relative to the WXS file. The GUI tool uses the location of the WXS and the SourceDir to enumerate the source structure for drag / drop operations and then uses it to author the File elements like such.

<?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="DesktopApplicationMM" Language="1033" Version="1.0.0.0">
    <Package Id="04cfbb1b-8105-4f3e-9b7a-c1d5354dc670" Manufacturer="DesktopApplicationMM" InstallerVersion="200" />
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="DesktopFolder" />
      <Directory Id="MergeRedirectFolder">
        <Component Id="owc17DECDE7A34AF545285829FF09EF24AE" Guid="4791fdfe-28ff-3c07-2f9e-e2f418c712f8">
          <File Id="owf17DECDE7A34AF545285829FF09EF24AE" Source="$(var.SourceDir)\DesktopApplication.exe" KeyPath="yes">
            <Shortcut Id="sc06A337B51AED2DF7E22F894A213D2792" Name="Desktop Application" Directory="DesktopFolder" />
          </File>
        </Component>
      </Directory>
    </Directory>
    <ComponentGroupRef Id="Custom" />
  </Module>
</Wix>

If you ever refactor where the files come from you only have one line to update.

Upvotes: 1

Related Questions