You need to use Xpath. If you use addelement without an xpath then you can't add the same element more than once. This isn't too well documented. This should work for you
<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks"/> <ItemGroup> <Itemgroup Include="1"> <ID>RE1</ID> </Itemgroup> <Itemgroup Include="2"> <ID>RE2</ID> </Itemgroup> <Itemgroup Include="3"> <ID>RE3</ID> </Itemgroup> </ItemGroup> <Target Name="Default"> <XmlFile TaskAction="AddElement" File="d:\a\pathtoxmlfile.xml" Element="RenderEngine" ParentElement="//RenderingConfiguration/RenderEngines" XPath="//RenderingConfiguration/RenderEngines" Key="ID" Value="%(Itemgroup.ID)" /> </Target> </Project>