Question

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.

Was it helpful?

Solution

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:\"/> 

OTHER TIPS

Just put the single file name as the value for "SourceFiles". Easy-Peezey.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="AllTargetsWrapper" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <WorkingCheckout>.</WorkingCheckout>
    </PropertyGroup>

    <Target Name="AllTargetsWrapper">
        <CallTarget Targets="CopyItTarget" />
    </Target>

    <Target Name="CopyItTarget">
        <Copy SourceFiles="c:\windows\system.ini" DestinationFolder="$(WorkingCheckout)\"/>     
        <Error Condition="!Exists('$(WorkingCheckout)\system.ini')" Text="No Copy Is Bad And Sad" />
    </Target>

</Project>

For what it's worth, I needed to do the same thing, and wanted to put some version information in the file name. Here is how I did it for a project in $(SolutionDir) that references an executable created by another project in another solution that I can easily express the path to:

  <Target Name="AfterBuild">
    <GetAssemblyIdentity AssemblyFiles="$(SolutionDir)..\bin\$(Configuration)\SomeExectuable.exe">
      <Output TaskParameter="Assemblies" ItemName="AssemblyVersions" />
    </GetAssemblyIdentity>
    <CreateProperty Value="$(TargetDir)$(TargetName)-%(AssemblyVersions.Version)$(TargetExt)">
      <Output TaskParameter="Value" PropertyName="NewTargetPath" />
    </CreateProperty>
    <Copy SourceFiles="$(TargetPath)" DestinationFiles="$(NewTargetPath)" />
  </Target>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top