Trying to exclude certain extensions doing a recursive copy (MSBuild)

Posted by Kragen on Stack Overflow See other posts from Stack Overflow or by Kragen
Published on 2010-06-13T04:01:48Z Indexed on 2010/06/13 4:12 UTC
Read the original article Hit count: 581

Filed under:
|
|

I'm trying to use MSBuild to read in a list of files from a text file, and then perform a recursive copy, copying the contents of those directories files to some staging area, while excluding certain extensions (e.g. .tmp files)

I've managed to do most of the above quite easily using CreateItem and the MSBuild copy task, whatever I do the CreateItem task just ignores my Exclude parameter:

<PropertyGroup>
  <RootFolder>c:\temp</RootFolder>
  <ExcludeFilter>*.tmp</ExcludeFilter>
  <StagingDirectory>staging</StagingDirectory>
</PropertyGroup>
<ItemGroup>
  <InputFile Include="MyFile.txt" />
</ItemGroup>

<Target Name="Build">
  <ReadLinesFromFile File="@(InputFile)">
    <Output ItemName="AllFolders" TaskParameter="Lines" />
  </ReadLinesFromFile>

  <CreateItem Include="$(RootFolder)\%(AllFolders.RelativeDir)**"
              Exclude="$(ExcludeFilter)">
    <Output ItemName="AllFiles" TaskParameter="Include" />
  </CreateItem>

  <Copy SourceFiles="@(AllFiles)"
        DestinationFolder="$(StagingDirectory)\%(RecursiveDir)" 

Example contents of 'MyFile.txt':

somedirectory\
someotherdirectory\

(I.e. the paths are relative to $(RootFolder) - mention this because I read somewhere that it might be relevant)

I've tried loads of different combinations of Exclude filters, but I never seem to be able to get it to correctly exclude my .tmp files - is there any way of doing this with MSBuild without resorting to xcopy?

© Stack Overflow or respective owner

Related posts about msbuild

Related posts about exclude