WiX Relative Path to the Source File

wix
Christian Sauer picture Christian Sauer · Oct 19, 2012 · Viewed 29.4k times · Source

I have a simple Solution for my Project, which works well. But I am unable to grasp how to make the Source paths relative. Can somebody help me?

  <Component Id="Bla.exe" Guid="*">
    <File Id="Bla.exe" Source="D:\Projects\Bla\Bla\bin\Debug\Bla.exe" KeyPath="yes" Checksum="yes"/>
  </Component>

How can I make the Path relative to the Wix Solution? WiX and all necessary files are in the same Solution.

Answer

BryanJ picture BryanJ · Oct 19, 2012

You can use the relative path like so:

    <File Id="Bla.exe" Source="..\bin\Debug\Bla.exe" KeyPath="yes" Checksum="yes"/>

OR

You can add a configuration file to your project to define common variables. To do so, add a new "WiX Include" file to your project, call it config.wxi. Then in your include file, you can define a SourceDir variable like so:

<?xml version="1.0" encoding="utf-8"?>
<Include>
  <?define SourceDir = "D:\Projects\Bla\Bla\bin\Debug" ?>
</Include>

Now in your .wxs file, you can add a reference to the config file at the top, ex:

<?xml version="1.0" encoding="UTF-8"?>
 <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
 <?include "config.wxi"?>

Then just reference your SourceDir variable like so:

<File Id="Bla.exe" Source="$(var.SourceDir)\Bla.exe" KeyPath="yes" Checksum="yes"/>

Also, there are some built in WiX project variables that you may use.