Any way to create a new XML file?

Mar 27, 2012 at 9:06 PM

I saw from the documentation that XmlFile allows for Add/Remove Attribute/Element.  Is there something I missed that can create a new xml file?

Mar 28, 2012 at 12:05 AM



Do you see any benefit that this would provide over the WriteLinesToFile task?



Mar 28, 2012 at 4:38 PM

I'm trying to create a new XML and it seems like I need to create a xml file with a root but no content, save it, then populate it with XmlFile.  I might be missing something though as I'm new to MSBuild (have been scouring the web for assistance though).  I'm also probably being lazy, but I would think that there would've been a task to create a XML file based on the contents of an Itemgroup and specified prologue for the file.

Mar 28, 2012 at 8:20 PM

Can you expand on your thoughts "create a XML file based on the contents of an Itemgroup and specified prologue for the file"... I'll see what can be done for the upcoming release due in a few days.



Mar 28, 2012 at 10:26 PM
Edited Mar 28, 2012 at 10:29 PM

Hi Mike, thanks for the quick response.

What I'm doing now is this:

  <!-- Create the xml file -->
    <XMLLines Include="&lt;?xml version=%221.0%22 encoding=%22utf-8%22 standalone=%22yes%22?&gt;"/>
    <XMLLines Include="&lt;!--Some kind of comment--&gt;"/>
    <XMLLines Include="&lt;root&gt;&lt;/root&gt;"/>

    <MyXMLFile Include="myfilename.xml">
    <MyXMLFile Include="myfilename.xml">
    <MyXMLFile Include="myfilename.xml">

  <Target Name="CreateMyXML">
    <!-- Create the original file, since XmlFile only edits a xml file -->
    <WriteLinesToFile File="myfilename.xml" Lines="@(XMLLines)" Encoding="UTF-8" Overwrite="true"/>
    <!-- Populate the file with data -->
    <MSBuild.ExtensionPack.XML.XmlFile TaskAction="AddElement"



I originally thought that MSBuild would have a XML document creation task instead of having to write the declaration, having to deal with such things as reserved characters (which I'm not sure can be avoided), and wouldn't require two steps of creating a file and then populating it with data.