簡體   English   中英

Wix:在自定義操作中寫入文件

[英]Wix: Write File in Custom Action

我遇到了wix和管理自定義操作的問題:在我的自定義操作中,我創建了一個文件並將其保存在INSTALLLOCATION路徑中。 似乎它有效,沒有拋出異常。 但安裝后,剛剛創建的 File 不存在於INSTALLLOCATION中。

WiX 文件:

<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>

自定義操作方法:

...
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);
...

任何人的想法?

已編輯:在 Scott Boettger 發布后,您編輯了 wix 文件內容。

我不認為你的配置是正確的。 以下是一些問題:

  1. 您不應該在 InstallExecuteSequence 中使用私有屬性(CREATE_TIME_STAMP 比 CreateTimeStamp 好,因為它是公共屬性)。
  2. 您正在設置 CreateTimeStamp 屬性並在自定義操作中讀取 CustomActionData。 您應該將CustomActionData屬性設置為 INSTALLLOCATION 路徑。
  3. 由於您的自定義操作是在安裝文件夾中創建一個文件,因此它應該作為延遲運行,並且Impersonate屬性應該設置為“no”。 這樣,它將有足夠的權限來創建文件。

嘗試進行這些修改,看看問題是否仍然存在。

我相信您的自定義操作需要介於 InstallInitialize 和 InstallFinalize 之間。 嘗試這個:

<InstallExecuteSequence>
  <Custom Action="SetInstallPath" After="InstallInitialize"/>
  <Custom Action="CreateTimeStamp" Before="InstallFinalize"/>
</InstallExecuteSequence>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM