【发布时间】:2016-01-27 10:38:19
【问题描述】:
我已经引用了this 问题,因为我需要在 WIX 安装期间编辑一个不是 xml 文件的文件。我正在通过 wix 部署一个网站,我需要根据用户输入在一个文件中进行一些更改。
以下是我的自定义操作
<CustomAction Id="CustomActionID_Data" Property="CustActionId" Value="FileId=[#filBEFEF0F677712D0020C7ED04CB29C3BD];MYPROP=[MYPROP];"/>
<CustomAction Id="CustActionId"
Execute="deferred"
Impersonate="no"
Return="ignore"
BinaryKey="CustomActions.dll"
DllEntry="EditFile" />
以下是自定义操作中的代码。
string prop= session.CustomActionData["MYPROP"];
string path = session.CustomActionData["FileId"];
StreamReader f = File.OpenText(path);
string data = f.ReadToEnd();
data = Regex.Replace(data, "replacethistext", prop);
File.WriteAllText(path, data); // This throws exception.
由于这是在 IIS 的 intetpub 文件夹下,我的操作会引发错误,即文件正在被另一个进程使用。有什么解决办法吗?
如果需要知道我的执行顺序,它是在 installfiles 之后,所以站点还没有启动,但是文件被复制了。
<InstallExecuteSequence>
<Custom Action="CustomActionID_Data" Before="CustActionId">NOT REMOVE</Custom>
<Custom Action="CustActionId" After="InstallFiles">NOT REMOVE</Custom>
</InstallExecuteSequence>
【问题讨论】:
-
只是想一想,WIX 安装程序本身是否已经掌握了该文件,并且由于同样的原因,自定义操作无法修改它?如果是,那该怎么办?