I am having a heck of time trying get my mind wrapped around the way to create
and use a custom action in my C# Wix Project in Visual Studio 2013.
I want to be able to open a specified XML file and return an attribute from a
specified key and then use that to initialized a property in the installer and
display it in the dialog. Then when installer is run it will write the value
to a target XML file to the same key and attribute. In My case I have a
MAC_ID Property that is in a UI text box that I want to initialize from a XML
file attribute and then write to a new XML file during the install. The write
is pretty straightforward since it is built into WIx. But I can't get the read
working.
I created this Custom Action
public class CustomActions
{
[CustomAction]
public static ActionResult ReadXmlValue(Session session)
{
string fileName = session.CustomActionData["FileName"];
string xmlnode = session.CustomActionData["Node"];
string key = session.CustomActionData["Key"];
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(fileName);
if (xmlDoc.DocumentElement != null)
{
XmlNodeList nodeList =
xmlDoc.DocumentElement.SelectNodes(xmlnode);
if (nodeList != null)
foreach (XmlNode node in nodeList)
{
var selectSingleNode = node.SelectSingleNode(key);
if (selectSingleNode != null) session["Value"] =
selectSingleNode.InnerText;
}
}
return ActionResult.Success;
}
}
My WXS script looks like this
<Property Id="MAC_ID" Secure="yes" Value="0"/>
<Property Id="MACIDTemplate">
<![CDATA[&&-&&-&&-&&-&&-&&]]>
</Property>
<CustomAction Id="myActionId" BinaryKey="myAction" DllEntry="ReadXMLValue"
Execute="deferred" Return="check" />
<CustomAction Id="SetCustomActionDataValue" Return="check"
Property="myActionId" Value="FileName='.\FilesToInstall\Program
Files\Zygo\MetroProX\cfg\NewView.IC.xml';Node='\Settings\Section\Section\Section\add';Key='Mac'"
/>
<CustomAction Id="ReadXMLValue" Property="Value" Value="[MAC_ID]" />
<InstallExecuteSequence>
<Custom Action="SetCustomActionDataValue" Before="myActionId">NOT
Installed</Custom>
<Custom Action="myActionId" Before="InstallFinalize">NOT
Installed</Custom>
</InstallExecuteSequence>
But I don't think I have this setup right?
Jeff Davis
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
WiX-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wix-users