Skip to content

Instantly share code, notes, and snippets.

@dtwk2
Last active March 28, 2020 09:44
Show Gist options
  • Save dtwk2/b52d7236ecdd2fd6c2f0b06709c7f99f to your computer and use it in GitHub Desktop.
Save dtwk2/b52d7236ecdd2fd6c2f0b06709c7f99f to your computer and use it in GitHub Desktop.
Best solution (to copy to .csproj file)
- Runs after packing
- RoboCopy needs space after path arg e.g "..\df sd " if path has spaces in it otherwise do not include space.
- /XO ignores newer files in source
- /NFL /NDL /NJH partially removes RoboCopy output
- Since RoboCopy had different exit codes than MSBuild and many don't indicate error; need last two lines
<Target Name="PostPack" AfterTargets="Pack">
<Exec Command="
set source=&quot;$(ProjectDir)$(OutDir).. &quot;&#xD;&#xA;
set target=&quot;..\NugetPackages &quot; &#xD;&#xA;
RoboCopy %25source%25 %25target%25 *.nupkg /XO /NFL /NDL /NJH &#xD;&#xA;
IF %ERRORLEVEL% GEQ 8 exit 1&#xD;&#xA;
exit 0" />
</Target>
Won't work
xcopy will overwrite files if they were generated on different dates
dotnet pack --no-build --output nupkgs --include-source --include-symbols
set store="<name of nuget package store directory>"
for %%f in ("$(ProjectDir)$(OutDir)..\*.nupkg") do xcopy %%f %store% /Y /I /D
or alternativaly
<Target Name="PostPack" AfterTargets="Pack">
<Exec Command="&#xD;&#xA;set store=&quot;<name of nuget package store directory>&quot;&#xD;&#xA;for %25%25f in (&quot;$(ProjectDir)$(OutDir)..\*.nupkg&quot;) do xcopy %25%25f %25store%25 /Y /I /D" />
</Target>
@dtaylor-530
Copy link

@dtaylor-530
Copy link

robocopy c:\Sourcepath c:\Destpath /E /XC /XN /XO

:: /E makes Robocopy recursively copy subdirectories, including empty ones.
:: /XC excludes existing files with the same timestamp, but different file sizes. Robocopy normally overwrites those.
:: /XN excludes existing files newer than the copy in the source directory. Robocopy normally overwrites those.
:: /XO excludes existing files older than the copy in the source directory. Robocopy normally overwrites those.
:: With the Changed, Older, and Newer classes excluded, Robocopy will exclude files existing in the destination directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment