0
votes

I have reffered this question as I need to edit a file during WIX installation which is not a xml file. I am deploying a web site through wix and I need to make some changes in one file according to the user input.

Below are my custom actions

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

and below is the code in custom action.

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.

As this is under IISs intetpub folder my action throws error that file is being used by another process. Any solutions?

If need to know my execution sequence, it is after installfiles so site is not yet started but files are copied.

<InstallExecuteSequence>
  <Custom Action="CustomActionID_Data" Before="CustActionId">NOT REMOVE</Custom>
  <Custom Action="CustActionId" After="InstallFiles">NOT REMOVE</Custom>
</InstallExecuteSequence>
1
Just a thought, is WIX installer itself have got hold of that file and custom action can not modify it because of same reason? If so then what to do?Chaitanya Gadkari

1 Answers

0
votes

Okay, I got this solved. This was neither wix issue nor execution sequence. In code above I have opened a stream to read text and did not dispose it after reading, that's what was holding my resource. I changed code to below and everything is working fine.

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