简体   繁体   中英

Copy files only they were changed

I need to copy some files after build if they were changed. Following is my copy scripts:

  <Target Name="CopyFiles" AfterTargets="Build">
    <ItemGroup>
      <DeployFileGroup Include="**\*.json;**\*.png;**\*.wav;**\*.mp3;" />
    </ItemGroup>
    <Copy SourceFiles="@(DeployFileGroup)"
      DestinationFolder="C:\Test"/>
  </Target>

But it executed every time when I build the project, what I want it just executed when the file is modified.

what I want it just executed when the file is modified.

You can set the SkipUnchangedFiles to true to achieve your requirement.

  <Target Name="CopyFiles" AfterTargets="Build">
    <ItemGroup>
      <DeployFileGroup Include="**\*.json;**\*.png;**\*.wav;**\*.mp3;" />
    </ItemGroup>
    <Copy SourceFiles="@(DeployFileGroup)"
      DestinationFolder="C:\Test" SkipUnchangedFiles="true"
      />
  </Target>

With this setting, those files only copied when they were changed. If not, they will not copied, then give you the message like:

1>Task "Copy"
1>  Did not copy from file "Test.json" to file "C:\Test\Test.json" because the "SkipUnchangedFiles" parameter was set to "true" in the project and the files' sizes and timestamps match.
1>  Did not copy from file "Test1.json" to file "C:\Test\Test1.json" because the "SkipUnchangedFiles" parameter was set to "true" in the project and the files' sizes and timestamps match.
1>  Did not copy from file "Test.png" to file "C:\Test\Test.png" because the "SkipUnchangedFiles" parameter was set to "true" in the project and the files' sizes and timestamps match.
1>  Did not copy from file "Test1.png" to file "C:\Test\Test1.png" because the "SkipUnchangedFiles" parameter was set to "true" in the project and the files' sizes and timestamps match.
1>  Did not copy from file "Test.wav" to file "C:\Test\Test.wav" because the "SkipUnchangedFiles" parameter was set to "true" in the project and the files' sizes and timestamps match.
1>  Did not copy from file "Test1.mp3" to file "C:\Test\Test1.mp3" because the "SkipUnchangedFiles" parameter was set to "true" in the project and the files' sizes and timestamps match.
1>Done executing task "Copy".

Hope this helps.

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