WiX Preprocessor <?define?> created progromatically in C Sharp
I have a WiX file that is updated automatically and programmatically. This file needs to have a define tag added to it, but I can't find a method for doing this with C#. Every time I try to add an element it says that it is not contained in the root element (which is true cause the "define" is a preprocessor command and is not included in the root element). In order to edit the XML tag (that is also preprocessor) there is built in functionality. Does anyone know if there is al开发者_如何学JAVAso built in functionality for define? Thanks for your help!
If you're using an XmlWriter, use the WriteProcessingInstruction to write a processing instruction. If you're using XSLT, use xsl:processing-instruction. If you're using a different C# mechanism to create your XML, tell us - most mechanisms have facilities to create processing instructions.
Here's a function I'm using for the same task
static void WritePreProcessor(Parameters p)
{
XmlDocument doc = new XmlDocument();
doc.Load(p.InputXml);
XmlProcessingInstruction pi = doc.CreateProcessingInstruction(p.Name, p.Value);
XmlNode root = doc.DocumentElement;
doc.InsertBefore(pi, root);
doc.Save(p.OutputXml);
}
with p.Name = "define", and p.Value = "SourceDir=....\build", the result looks like
<?xml version="1.0" encoding="utf-8"?>
<?define SourceDir=..\..\build?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
...
</Fragment>
</Wix>
I think you will have to edit your file in 'text' mode, not in XML mode. One possible solution is to insert special markers in your file in XML mode, e.g.
<a_very_special_marker/>
And then do a replace on these markers on the text of the file.
精彩评论