在 Wix 自定义操作中编辑 inetpub 文件夹中的文件
Edit file from inetpub folder in wix custom action
我已提交 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 问题也不是执行顺序。在上面的代码中,我打开了一个流来读取文本并且在阅读后没有处理它,这就是我的资源。我将代码更改为以下,一切正常。
string data = "";
string prop= session.CustomActionData["MYPROP"];
string path = session.CustomActionData["FileId"];
using(StreamReader f = File.OpenText(path)) // disposed StreamReader properly.
{
data = f.ReadToEnd();
data = Regex.Replace(data, "replacethistext", prop);
}
File.WriteAllText(path, data);
我已提交 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 问题也不是执行顺序。在上面的代码中,我打开了一个流来读取文本并且在阅读后没有处理它,这就是我的资源。我将代码更改为以下,一切正常。
string data = "";
string prop= session.CustomActionData["MYPROP"];
string path = session.CustomActionData["FileId"];
using(StreamReader f = File.OpenText(path)) // disposed StreamReader properly.
{
data = f.ReadToEnd();
data = Regex.Replace(data, "replacethistext", prop);
}
File.WriteAllText(path, data);