msbuild to copy to multiple locations defined in item metadata -
i have item metadata want copy perform actions on , result occur in multiple locations, example, want copy file multiple locations:
<itemgroup> <myitem include="myfile.txt"> <out>c:\blah;c:\test</out> </myitem> </itemgroup>
how setup target create c:\blah , c:\test if dont exist, copy myfile.txt c:\blah\myfile.txt , c:\test\myfile.txt
i want list of full output paths (c:\blah\myfile.txt , c:\test\myfile.txt) if want clean them during clean.
if dont want change structure of itemgroup, need handle have nested itemgroup (the metadataelement out). therefor need batch itemgroup myitem target , inside can batch out. made small example project:
<?xml version="1.0" encoding="utf-8"?> <project defaulttargets="copyfiles" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" toolsversion="3.5"> <itemgroup> <myitem include="myfile.txt"> <out>c:\blah;c:\test</out> </myitem> <myitem include="myfile2.txt"> <out>c:\blah2;c:\test2</out> </myitem> </itemgroup> <target name="copyfiles" inputs="%(myitem.identity)" outputs="%(myitem.identity)\ignore_this.msg"> <propertygroup> <file>%(myitem.identity)</file> </propertygroup> <itemgroup> <folders include="%(myitem.out)" /> </itemgroup> <message text="%(folders.identity)\$(file)" /> </target> </project>
the output be:
project "d:\temp\test.proj" on node 1 (default targets). copyfiles: c:\blah\myfile.txt c:\test\myfile.txt copyfiles: c:\blah2\myfile2.txt c:\test2\myfile2.txt done building project "d:\temp\test.proj" (default targets). build succeeded. 0 warning(s) 0 error(s)
Comments
Post a Comment