Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing an absolute path to a custom action in WiX

Tags:

wix

wix3.5

I'm using WiX to create an installer for my application

I have this fragment which describes the destination install folder for my application:

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="CommonAppDataFolder">
        <Directory Id="Company" Name="myCompany">
          <Directory Id="App" Name="myProgram">
            <Directory Id="SQLGENERATORINSTALLFOLDER" Name="SqlLiteFolder" />
          </Directory>          
        </Directory>
      </Directory>
    </Directory>
  </Fragment>

I also have a custom action which requires the [App] folder as an input parameter. If I pass [App] to the custom action I would expect the entire path of the folder, from C:\ all the way down to the inner folder

I would expect this:

C:\ProgramData\myCompany\myProgram\

Instead, I get this:

C:\Windows\Installer\MSI971.tmp-C:\ProgramData\myCompany\myProgram\

Looks like WiX is appending a temporary folder of some sort

EDIT

This is how I pass the [App] variable to the custom action:

  <CustomAction Id='GrantAccessToDatabase' BinaryKey='ActionLib' DllEntry='GrantAccess' Execute='deferred' Impersonate='no' />
  <Property Id="GrantAccessToDatabase" Value="DbFilePath=[App]" />

Please note that in order to pass a variable to a deferred custom action I need to use that syntax, it's explained here -> How to pass parameters to the custom action?

That's the C# part which receive the parameter:

[CustomAction]
public static ActionResult GrantAccess(Session session)
{
     var data = session.CustomActionData;
     var fullPath = data["DbFilePath"];
}

I would expect fullPath to be:

C:\ProgramData\myCompany\myProgram\

Instead, I get:

C:\Windows\Installer\MSI971.tmp-C:\ProgramData\myCompany\myProgram\

like image 720
Gianluca Ghettini Avatar asked Oct 30 '22 10:10

Gianluca Ghettini


1 Answers

Most cases, your installer is cached hence the temporary folder. You can instead concatenate the full path: <...Value="DbFilePath=[CommonAppDataFolder]\myCompany\myProgram" />.

like image 147
Geoff Avatar answered Dec 08 '22 06:12

Geoff