How to use MSBuild transform when ItemGroup files all have identical names? -
i have bunch of files x.txt in various directories throughout project. part of build step, collect these , place them in single folder (without needing declare each one). can detect them using:
<itemgroup> <myfiles include="$(srcroot)\**\x.txt"/> </itemgroup>
however, if copy these single folder - overwrite each other. have tried using transform append guid each file name, guid created once, , re-used each transform (thus overwrite each over). there way of generating unique names in msbuild when copying itemgroup identically named files? end naming scheme not important, long files end in folder.
the transform works have 'force' generate new data on each iteration. took me while figure out , makes sense couldn't find documentation explaining this. works referencing other existing metadata: msbuild sees has evaluated on every iteration happily evaluate part of new metadata. example, using %(filename):
<target name="createuniquenames"> <itemgroup> <myfiles include="$(srcroot)\**\x.txt"/> <myfiles> <dest>%(filename)$([system.guid]::newguid())%(filename)</dest> </myfiles> </itemgroup> <message text="%(myfiles.identity) -> %(myfiles.dest)"/> </target>
alternatively can make use of unique metadata have namely recursivedir:
<target name="createuniquenames"> <itemgroup> <myfiles include="$(srcroot)\**\x.txt"/> <myfiles> <dest>x_$([system.string]::copy('%(recursivedir)').replace('\', '_')).txt</dest> </myfiles> </itemgroup> <message text="%(myfiles.identity) -> %(myfiles.dest)"/> </target>
Comments
Post a Comment