Reputation: 173
I'm a C# and WiX relative newbie
My goal was to pass three parameters (InputString, SearchString, ReplaceString) in order to transform a path for use in an erlang (erl.ini) file, which requires double backslashes in Windows.
My hope was to be able to access an OutputString to set a property in my WiX project.
Here's my C# customaction code
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace DGCustomActions
{
public class CustomActions
{
[CustomAction]
public static ActionResult CASearchAndReplace(Session session)
{
try
{
session.Log("Begin CASearchAndReplace");
string InputString = session.CustomActionData["InputString"];
string SearchString = session.CustomActionData["SearchString"];
string ReplaceString = session.CustomActionData["ReplaceString"];
session["OutputString"] = InputString.Replace(SearchString, ReplaceString);
session.Log("CASearchAndReplace Successful");
}
catch (Exception ex)
{
session.Log("ERROR in custom action CASearchAndReplace: {0}",
ex.ToString());
return ActionResult.Failure;
}
return ActionResult.Success;
}
}
}
Here's my attempt at passing parameters and running the customaction
<CustomAction Id='PassValuesErlangBindir'
Execute='immediate'
Property='TransformErlangBindir'
Value='InputString=[ERLANGERTSBINDIR];SearchString=\;ReplaceString=\\' />
<CustomAction Id='TransformErlangBindir'
BinaryKey='DGCustomActions'
DllEntry='CASearchAndReplace'
Execute='deferred'
Return='check' />
I currently have no code for accessing the OutputString property
Any help would be greatly appreciated
Upvotes: 1
Views: 1790
Reputation: 173
After reading Rolo's (thank you for the input) earlier post more carefully, I made the following changes which did the trick.
Note: If anyone has suggestions that would make my solution cleaner, I'd appreciate hearing from you.
Here's my updated C# customaction code
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace DGCustomActions
{
public class CustomActions
{
[CustomAction]
public static ActionResult SearchAndReplace(Session session)
{
session.Log("Begin SearchAndReplace");
string InputString = session["InputString"];
string SearchString = session["SearchString"];
string ReplaceString = session["ReplaceString"];
session["OutputString"] = InputString.Replace(SearchString, ReplaceString);
session.Log("SearchAndReplace Successful");
return ActionResult.Success;
}
}
}
Here's my updated set of customactions
<CustomAction Id="Set.SearchString" Property="SearchString" Value="\" />
<CustomAction Id="Set.ReplaceString" Property="ReplaceString" Value="\\" />
<CustomAction Id="Set.OutputString" Property="OutputString" Value="nada" />
<CustomAction Id="Set.ErlangBindir.InputString" Property="InputString" Value="[ERLANGDIR]erts-$(var.ErlangVersion)\bin" />
<CustomAction Id="Transform.ErlangBindirString"
BinaryKey="DGCustomActions"
DllEntry="SearchAndReplace"
Execute="immediate"
Return="check" />
<CustomAction Id="Set.ErlangBindir.OutputString" Property="ErlangBindir" Value="[OutputString]" />
<CustomAction Id="Set.ErlangRootdir.InputString" Property="InputString" Value="[ERLANGDIR]bin" />
<CustomAction Id="Transform.ErlangRootdirString"
BinaryKey="DGCustomActions"
DllEntry="SearchAndReplace"
Execute="immediate"
Return="check" />
<CustomAction Id="Set.ErlangRootdir.OutputString" Property="ErlangRootdir" Value="[OutputString]" />
Here's my updated Install Execute Sequence
<InstallExecuteSequence>
<!-- Run after InstallInitialize: Sequence="1500" -->
<Custom Action="Set.SearchString" Sequence="1501" />
<Custom Action="Set.ReplaceString" Sequence="1502" />
<Custom Action="Set.OutputString" Sequence="1503" />
<Custom Action="Set.ErlangBindir.InputString" Sequence="1504" />
<Custom Action="Transform.ErlangBindirString" Sequence="1505" />
<Custom Action="Set.ErlangBindir.OutputString" Sequence="1506" />
<Custom Action="Set.ErlangRootdir.InputString" Sequence="1507" />
<Custom Action="Transform.ErlangRootdirString" Sequence="1508" />
<Custom Action="Set.ErlangRootdir.OutputString" Sequence="1509" />
</InstallExecuteSequence>
Upvotes: 1