views:

976

answers:

2

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>
A: 

Just use a regular pre- or post-build event. VS supports this out of the box.

xcopy "@(TargetDir)*.dll" "\yourdir" /i /f /s /v /y
cdonner
Thanks, but I need to do this using MSBuild.
Dave
+2  A: 

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

Scott Weinstein
Visual Studio reports the error, "The element <SourceFiles> beneath element <ItemGroup> is unrecognized." Any ideas?
Dave
Ok, when researching this I saw the CreateItem task mentioned, I'll take another look.
Dave