Copy a single file in MSBuild without using Exec or ItemGroup

Shaun picture Shaun · Nov 12, 2013 · Viewed 8.7k times · Source

Is there any way to do this? I just need to copy a single file and thought there may be some syntax for the SourceFiles parameter of the Copy task that means you don't need to define an ItemGroup beforehand, I'd rather stick with ItemGroup than use Exec though.

Answer

James Woolfenden picture James Woolfenden · Nov 14, 2013

Copy files also takes a straight propertygroup as input:

<PropertyGroup>
  <SourceFile>Some file</SourceFile>
</PropertyGroup>
<Copy SourceFiles="$(SourceFile)" DestinationFolder="c:\"/> 

Or even just a string

<Copy SourceFiles="Pathtofile" DestinationFolder="c:\"/>