Search code examples
c#wixcustom-action

Get file from MSI in wix Custom Action (Before="InstallFinalize")


Need to CustomAction during installation to get the file nlbdb.bak from MSI. How to get his path?

<Directory Id="ProgramFilesFolder">
  <Directory Id="BACKUP" Name="BACKUP"/>
<Directory/>
<DirectoryRef Id="BACKUP">
  <Component Id="VMBackup">
    <File Id="Backup" Name="nlbdb.bak" Source="BACKUP\nlbdb.bak" DiskId="1" KeyPath="yes" />
  </Component>
</DirectoryRef>

CA

[CustomAction]
public static  ActionResult CustomAction1(Session session)
{
  string Directory = "";//get file path nlbdb.bak
  bool test = File.Exists(Directory);
}

Solution

  • You can access a wix property inside your custom action using

    var propertyValue = session["MY_PROPERTY"];
    

    In your case you'd use that to get the value of BACKUP which will be where the file was installed. Obviously you would also concatenate the file name as needed.