Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I copy files to another directory using MSBuild?

I'm trying to copy several files in the $(TargetDir) to another folder (e.g. C:\BinCache), but for whatever reason I cannot get MSBuild to stop complaining.

  <Target Name="AfterBuild">
    <Copy SourceFiles="$(TargetDir)\*.*"
          DestinationFolder="C:\BinCache" />
  </Target>

What am I doing wrong here?

EDIT: The solution is to use a CreateItem task. Presumably, Visual Studio 2008 removes this restriction. Thanks Scott!

<Target Name="AfterBuild">
  <CreateItem Include="$(TargetDir)\*.*">
    <Output TaskParameter="Include" ItemName="SourceFiles" />
  </CreateItem>
  <Copy SourceFiles="@(SourceFiles)" DestinationFolder="C:\BinCache" />  
</Target>
like image 488
Dave Avatar asked Mar 17 '09 17:03

Dave


1 Answers

SourceFiles needs to be an Item list

you'll need something like

<Target Name="AfterBuild">
  <ItemGroup>
    <SourceFiles Include="$(TargetDir)\*.*" />
  </ItemGroup>
  <Copy SourceFiles="@(SourceFiles)" DestinationFolder="C:\BinCache" />  
</Target>

Just noticed you're on 2005, in that case you'll need to use the CreateItem task

like image 138
Scott Weinstein Avatar answered Jan 04 '23 02:01

Scott Weinstein