How to specify target dir during Copy Task in MSBu

2019-08-01 22:46发布

问题:

I have existing MSBuild code that I got help with but I need further help.

<!--?xml version="1.0" encoding="utf-8"?-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Demo">
    <ItemGroup>
        <Source1 Include="C:\temp\path01\**\*.txt" /> <!-- \%2A.txt -->
        <Target1 Include="C:\temp\path02" />
    </ItemGroup>
    <Target Name="Demo" BeforeTargets="Build;Rebuild">

        <!--<Exec Command="xcopy.exe /C /S /F /R /Y /I /D @(Source1) @(Target1)" />-->

        <Copy SourceFiles="@(Source1)" DestinationFiles="@(Source1->'@(Target1)\path02\%(RecursiveDir)%(Filename)%(Extension)')"
            SkipUnchangedFiles="true" />

        <Message Text="== END ===============================" />

    </Target>

</Project>

But seems like @(Target1) is not working. It actually creates the directory called @(Target1) instead of using Item value. See the result below.

Creating directory "@(Target1)\path02". Copying file from "C:\temp\path01\0001.txt" to "@(Target1)\path02\0001.txt". Copying file from "C:\temp\path01\0002.txt" to "@(Target1)\path02\0002.txt". Creating directory "@(Target1)\path02\sub". Copying file from "C:\temp\path01\sub\sub-0003.txt" to "@(Target1)\path02\sub\sub-0003.txt". Copying file from "C:\temp\path01\sub\sub-0004.txt" to "@(Target1)\path02\sub\sub-0004.txt". == END ===============================

I would like to avoid hard coding the destination dir if possible.
TIA.

标签: msbuild