Wix: write file in user action

I had a problem with wix and managed user actions: in my custom action, I create a file and save it in the INSTALLLOCATION path. This seems to work, no exception is thrown. But after installation, the newly created file does not exist in INSTALLLOCATION.

WiX file:

<CustomAction Id="SetInstallPath" Property="CreateTimeStamp" Value="[INSTALLLOCATION]" Execute="immediate"/> <CustomAction Id="CreateTimeStamp" BinaryKey="SetupActions.dll" DllEntry="CreateTimeStampFile" Execute="deferred" Return="check"/> <InstallExecuteSequence> <Custom Action="SetInstallPath" Before="InstallFinalize"/> <Custom Action="CreateTimeStamp" Before="InstallFinalize"/> </InstallExecuteSequence> 

Custom-Action-Methode:

 ... var keys = new string[session.CustomActionData.Keys.Count]; session.CustomActionData.Keys.CopyTo(keys, 0); var cad = keys[0]; var filepath = cad + "myfile.xml"; File.Create(filepath); ... 

Any idea?

Edited: after a message from Scott Bettger, the edited contents of the wix file.

+4
c # wix custom-action
source share
2 answers

I do not think your configuration is correct. Here are some of the problems:

  • You should not use private properties in InstallExecuteSequence (CREATE_TIME_STAMP is better than CreateTimeStamp because it is a public property).
  • You set the CreateTimeStamp property and read CustomActionData inside your custom action. You must set the CustomActionData strong> property to the INSTALLLOCATION path.
  • Since your custom action creates a file in the installation folder, it should work as pending, and the Impersonate attribute should be set to "no." Thus, he will have enough privileges to create the file.

Try making these changes and see if the problem persists.

+7
source share

I believe your custom actions should fall between InstallInitialize and InstallFinalize. Try the following:

 <InstallExecuteSequence> <Custom Action="SetInstallPath" After="InstallInitialize"/> <Custom Action="CreateTimeStamp" Before="InstallFinalize"/> </InstallExecuteSequence> 
+6
source share

All Articles