Wix: Write File in Custom Action

坚强是说给别人听的谎言 提交于 2019-12-31 00:50:27

问题


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.


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/5861178/wix-write-file-in-custom-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!