【问题标题】:Copy files only they were changed仅复制已更改的文件
【发布时间】:2018-03-12 05:34:13
【问题描述】:
如果它们被更改,我需要在构建后复制一些文件。以下是我的复制脚本:
<Target Name="CopyFiles" AfterTargets="Build">
<ItemGroup>
<DeployFileGroup Include="**\*.json;**\*.png;**\*.wav;**\*.mp3;" />
</ItemGroup>
<Copy SourceFiles="@(DeployFileGroup)"
DestinationFolder="C:\Test"/>
</Target>
但是每次构建项目时它都会执行,我希望它只是在修改文件时执行。
【问题讨论】:
标签:
c#
visual-studio-2015
msbuild
【解决方案1】:
我希望它在文件被修改时执行。
您可以将 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".
希望这会有所帮助。