Braces break %(RecursiveDir) in MSBuild


Update: 3 December 07 – The RTM version of MSBuild 2008 fixes this issue!

Summary

  • If braces ‘()’ are in the source path of a file copy operation that uses %(RecursiveDir), then the contents are copied to the root of the destination with no folder structure maintained.

Scope

  • This affects MSBuild 2005 & MSBuild 2008 (3.5) Beta 1 & Beta 2

Repro

  • Run the following on VS 2005 (add ToolsVersion=”3.5″ if running on VS2008)

<Project DefaultTargets=”DeployFiles” xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″>
       <ItemGroup>
              <FilesToCopy Include=”C:\Debug\SomeFolder\**\*.*”>
                     <Destination>D:\SomeFolderDebug</Destination>
              </FilesToCopy>
              <FilesToCopy Include=”C:\Debug (bug)\SomeFolder\**\*.*”>
                     <Destination>D:\SomeFolderDebugx86</Destination>
              </FilesToCopy>
       </ItemGroup>
       <Target Name=”DeployFiles”>
              <Copy SourceFiles=”%(FilesToCopy.Identity)” DestinationFolder=”%(FilesToCopy.Destination)\%(RecursiveDir)”/>
       </Target>
</Project>

  • The path without braces copies correctly and maintains folder structure.
  • The path with braces places all files into the root destination folder.
Workaround
  • Use exec and call out to xcopy
  • Write you own copy task!

Hopefully this gets fixed in Beta 2…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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