简体   繁体   中英

MSBUILD Copy multiple files from source paths to different destination paths

I need to copy the files from different source paths to different destination paths.

Example Sources:

  • xyz\\x.txt
  • pqr\\p.img

Corresponding Destinations:

  • mno\\x1.txt
  • qst\\p_sth.img

I am trying to use the batch copy as follows:

Created a ItemGroup specifying source file and destination files: Run batch Copy command:

<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         DefaultTargets="start">

<ItemGroup>
        <src Include="xyz\x.txt">
            <OutputFile>"mno\x1.txt"</OutputFile>
        </src>
        <src Include="pqr\p.img" >
            <OutputFile>"qst\p_sth.img"</OutputFile>
        </src>
</ItemGroup>

 <Target Name="start">


    <Message Importance="high" Text="Bulk Copy"/>
    <Copy SourceFiles="%(src.FullPath)" DestinationFiles="%(src.OutputFile)"/>
  </Target>
  </Project>

I am getting the "Illegal character" error pointing to line #17, shown as:

MSBuild错误 Can I even achieve this using Copy command? Also RoboCopy command is acceptable.

[But, requirement is we need full source path with file name and full destination path with file name]

What is the best approach to handle this?

The solution is just removing the unrequired quotes from the output file paths (As suggested by @stjin):

<ItemGroup>
        <src Include="xyz\x.txt">
            <OutputFile>mno\x1.txt</OutputFile>
        </src>
        <src Include="pqr\p.img" >
            <OutputFile>qst\p_sth.img</OutputFile>
        </src>
</ItemGroup>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM