How to do an MSBuild copy command that doesn't overwrite existing files?
msbuild
Solution
In your link there is an attribute "SkipUnchangedFiles". Add that to the copy task and set it to "true".
<Copy SourceFiles="@(Packages)" DestinationFolder="\\server\nuget\packages\" SkipUnchangedFiles="true" />
EDIT: I set up a sample project with the following.
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExistingPackages Include="dest\*.*" />
<Packages Include="src\*.*" Exclude="@(ExistingPackages -> 'src\%(FileName)%(Extension)')" />
</ItemGroup>
<Target Name="Build">
<Message Text="PackagesToCopy @(Packages)" Importance="high" />
</Target>
</Project>
Folder + file taxonomy is:
src\
doc1.txt
doc2.txt
doc3.txt
doc4.txt
doc5.txt
doc6.txt
dest\
doc2.txt
doc4.txt
doc6.txt
CopyNew.proj
When I run `msbuild.exe CopyNew.proj`, I get the following output:
Build:
PackagesToCopy src\doc1.txt;src\doc3.txt;src\doc5.txt
So now @(Packages) no longer contains the files that exist in the destination folder!
Problem
Looking at the documentation for the Copy task, I don't see an obvious way to copy files without overwriting existing files at the destination. I only want to copy new files. What I have so far: ``` <ItemGroup> <Packages Include=".nuget-publish\*.*" /> </ItemGroup> <Copy SourceFiles="@(Packages)" DestinationFolder="\\server\nuget\packages\" /> ```