【问题标题】:Edit file from inetpub folder in wix custom action在wix自定义操作中编辑inetpub文件夹中的文件
【发布时间】: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 安装程序本身是否已经掌握了该文件,并且由于同样的原因,自定义操作无法修改它?如果是,那该怎么办?

标签: file iis wix


【解决方案1】:

好的,我解决了这个问题。这既不是 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); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多