仅复制文件它们已被更改

时间:2018-03-12 05:34:13

标签: c# visual-studio-2015 msbuild

我需要在构建后复制一些文件,如果它们被更改的话。以下是我的复制脚本:

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

但每次构建项目时都会执行它,我希望它在修改文件时执行。

1 个答案:

答案 0 :(得分:2)

  

我希望它在修改文件时执行。

您可以将 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".

希望这有帮助。