Almost a month since posting Beware % in MSBuild, I find myself having to post on a similar topic.
Typically, $ is used all over the place in an MSBuild proj file, and in general you can use it without any cause for concern. An issue arises however, when you try to perform a recursive directory copy from an administrative share e.g. \\myserver\C$\myfolder.
If you use an administrative share as the source for a recursive copy, the folder structure is not maintained at the destination. All files are copied (from recursive folders in the source) to the destination folder. The workaround is to escape the $ with %24.
Let’s work with the following example:
<Project DefaultTargets="Prepare" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Copy SourceFiles="@(SomeFiles1)" DestinationFiles="@(SomeFiles1->’c:\SomeFolder1\%(RecursiveDir)%(Filename)%(Extension)’)"/>
<Copy SourceFiles="@(SomeFiles2)" DestinationFiles="@(SomeFiles2->’c:\SomeFolder2\%(RecursiveDir)%(Filename)%(Extension)’)"/>
<Copy SourceFiles="@(SomeFiles3)" DestinationFiles="@(SomeFiles3->’c:\SomeFolder3\%(RecursiveDir)%(Filename)%(Extension)’)"/>
SomeFiles1 – all files will all be copied to SomeFolder1 with no directory structure maintained. This is not expected behaviour !
SomeFiles2 – the files will be found and the directory structure will be maintained. This is expected behaviour .
SomeFiles3 – this is a new share mapped to the server path and behaviour will be as for SomeFiles2. This is expected behaviour .
Hopefully you read this post before being bitten like I was……cheers FTD.