仅复制已更改的文件

Copy files only they were changed

如果文件发生变化,我需要在构建后复制一些文件。以下是我的复制脚本:

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

但是我每次建工程的时候都会执行,我要的就是修改文件的时候执行

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

您可以将 SkipUnchangedFiles 设置为 true 来实现您的要求。

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

使用此设置,这些文件仅在更改时复制。如果没有,他们将不会复制,然后给你这样的消息:

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".

希望对您有所帮助。