How to create a XML file with MSBuild?
11,088
Quick and dirty...
<Target Name="CreateXml">
<ItemGroup>
<TestAssembly Include="$(TestsAssembliesOutputDir)\Emidee.*.Tests.dll" />
<Line Include="line01"><Text><xunit></Text></Line>
<Line Include="line02"><Text><assemblies></Text></Line>
<Line Include="line03"><Text><assembly filename="%(TestAssembly.Identity)" shadow-copy="true" /></Text></Line>
<Line Include="line04"><Text></assemblies></Text></Line>
<Line Include="line05"><Text></xunit></Text></Line>
<LineText Include="%(Line.Text)" />
</ItemGroup>
<WriteLinesToFile
File="out.xml"
Lines="@(LineText)"
Overwrite="true"
/>
</Target>
Left as an exercise for you
- The initial < ? xml line
- Indentation (hint use CDATA inside <`Text>)
You could also use the following in WriteLinesToFile and omit the synthesized @(LineText)
Lines="@(Line->'%(Text)')"
Related videos on Youtube
Comments
-
Emidee about 2 years
I'd like to create a XML file within a MSBuild task.
I have a list of files:
<CreateItem Include="$(TestsAssembliesOutputDir)\Emidee.*.Tests.dll"> <Output ItemName="TestsAssemblies" TaskParameter="Include" /> </CreateItem>
I'd like to create a XML which would look like:
<?xml version="1.0" encoding="utf-8"?> <xunit> <assemblies> <assembly filename="PATH OF FILE #1" shadow-copy="true" /> <assembly filename="PATH OF FILE #2" shadow-copy="true" /> </assemblies> </xunit>
How can I achieve that?
Thanks in advance
Mike