Beware $ in MSBuild 1.0

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=""&gt;


<SomeFiles1 Include="\\servername\d$\AFolder\**\*.*"/>

<SomeFiles2 Include="\\servername\d%24\AFolder\**\*.*"/>

<SomeFiles3 Include="\\servername\NewShare\**\*.*"/>


<Target Name="Prepare">

<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.

This entry was posted in MSBuild. Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s