4

i got a problem with wix and managed custom actions: in my custom action i create a file and save it in the INSTALLLOCATION path. It seems like it works, no exception is thrown. But after the installation, the just created File not exists in the 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);
...

Anyone a idea?

Edited: After the post from Scott Boettger y edited the wix-file content.

radbyx
  • 9,352
  • 21
  • 84
  • 127
rhe1980
  • 1,557
  • 1
  • 15
  • 36
  • 1
    You should accept the answer once you have the working solution. This will help you later on to have more people willing to help you. – Scott Boettger May 03 '11 at 12:57

2 Answers2

7

I don't think your configuration is correct. Here are some of the problems:

  1. You shouldn't use private properties in InstallExecuteSequence (CREATE_TIME_STAMP is better than CreateTimeStamp because it's a public property).
  2. You're setting the CreateTimeStamp property and reading CustomActionData inside your custom action. You should set the CustomActionData property to the INSTALLLOCATION path.
  3. Since your custom action is creating a file in the install folder, it should run as deferred and Impersonate attribute should be set to "no". This way it will have enough privileges to create the file.

Try making these modifications and see if the problem persists.

Cosmin
  • 21,216
  • 5
  • 45
  • 60
  • Hi Cosmin Pirvu, thank you so much for your answer. I sat the impersonate-property and now it works fine! Thank you! – rhe1980 May 02 '11 at 21:05
  • As a side note: This answer contains a nice gist with a sample http://stackoverflow.com/a/27299522/602449 – Robert Muehsig Feb 03 '17 at 10:28
6

I believe that your custom actions need to fall between InstallInitialize and InstallFinalize. Try this:

<InstallExecuteSequence>
  <Custom Action="SetInstallPath" After="InstallInitialize"/>
  <Custom Action="CreateTimeStamp" Before="InstallFinalize"/>
</InstallExecuteSequence>
Scott Boettger
  • 3,657
  • 2
  • 33
  • 44
  • thank you for your answer. in my post i wrote en error. my wix-file looks like this: The Problem I have is, that it looks like all works fine. I get no error and in the log-file i get the messege that the file has been generated. But after run the file does not exists in the installlocation.. – rhe1980 May 02 '11 at 20:19
  • Change both actions to execute deferred and you also shouldn't have them running at the same time. You currently have them both running Before="InstallFinalize". – Scott Boettger May 02 '11 at 20:28
  • When it was neither giving an error nor working, did you look in the `Compatibility files` area? (%LocalAppData%\VirtualStore\Program Files*\...; see http://stackoverflow.com/questions/5721736/wix-writing-new-file-from-custom-action/5755396#5755396) – Michael Urman May 03 '11 at 13:14