Why Does Robocopy Skip A File During Builds?

991 Views Asked by At

I added a robocopy file to my post build event in my C# project. X64 Release and Debug build fine, as does X86 Debug, however the X86 Release option does NOT copy the Get-Parent-Device.exe file to the target.

Why?

Note: I can always just add a step and copy over the file manually just for that specific configuration and that would "solve" my problem, however I want to understand what issue robocopy had. The source and destination are fine, permissions are fine, just X86/Release does not work.

What is interesting is that if I right click on the solution and select build, robocopy works on that configuration. What does not work is if I use Visual Build Professional and build all configurations of the project.

Here is the log+ file:

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows                              
-------------------------------------------------------------------------------

  Started : Tuesday, September 25, 2018 10:16:57 AM
   Source : C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\Get-Parent-Device\Release\
     Dest : C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x86\Release\

    Files : Get-Parent-Device.exe

  Options : /V /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30 

------------------------------------------------------------------------------

                       0    C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\Get-Parent-Device\Release\

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         0         0         0         0         0         0
   Bytes :         0         0         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : Tuesday, September 25, 2018 10:16:57 AM

Here are the relevant steps from the post build event:

robocopy /V /IS /log+:"$(TargetDir)robo.log" "$(ProjectDir)..\Get-Parent-Device\Release" $(TargetDir) Get-Parent-Device.exe
robocopy "$(ProjectDir)..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\$(PlatformName)" $(TargetDir) SQLite.Interop.dll
exit 0

Here is a screenshot of the build steps.

Visual Build Pro steps

I saw the recommendation to use /MIR, but I do not want to mirror, just copy that specific file. Sadly, /log, /log+, and /v do not provide very verbose information on why in this specific instance, robocopy felt the need to not copy over the file.

I do not like to sweep the problem under the rug or to to understand a technical problem, hence my post here. My concern is that if I cannot rely on Robocopy, then it might be a bad choice for use inside Visual Studio. I need a reliable copy, not an unreliable one.

XCOPY TRIAL:

That did not work. So far the best solution is still a Visual Build Pro instruction for that specific configuration. :-(

   PostBuildEvent:
     "C:\Program Files\Editors\VisBuildPro9\Tools\signtool.exe" sign /f  "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\jmrDigicert-2017-NoChain.pfx" /p 1234 /t http://timestamp.verisign.com/scripts/timstamp.dll "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\MyProject.exe"
     xcopy /i "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\Get-Parent-Device\Release\Get-Parent-Device.exe" C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\
     robocopy "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\x64" C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\ SQLite.Interop.dll
     robocopy "C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\..\Redistributables" C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\ AMBackup.exe
     exit 0

     Done Adding Additional Store
     Successfully signed and timestamped: C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\bin\x64\Debug\MyProject.exe

     C:\Users\Sarah\Source\Workspaces\MyProject\Flavor\Net\1.0\App\MyProject\..\Get-Parent-Device\Release\Get-Parent-Device.exe
     1 File(s) copied

     -------------------------------------------------------------------------------
        ROBOCOPY     ::     Robust File Copy for Windows                              
     -------------------------------------------------------------------------------
1

There are 1 best solutions below

9
On

Robocopy is designed to only copy changed files, but the option /IS you have added is suppose to copy whatever you like. Try to add parameter /IT (Includes "tweaked" files), but in my experience it is not reliable either.

This post How do I force Robocopy to overwrite files? confirm my findings. Their solution was same as mine: use XCOPY.

This https://superuser.com/questions/314503/what-does-robocopy-mean-by-tweaked-lonely-and-extra/445137#445137 table shows how robocopy groups files.

Edit:
The error message you get is typically that "file does not exists" in source.
Since your XCOPY test also failed then I'm 100% sure that the file does not exists.
Se example below:

C:\>dir x
 Volume in drive C has no label.
 Volume Serial Number is CE46-5CC1

 Directory of C:\x

25.09.2018  23:37    <DIR>          .
25.09.2018  23:37    <DIR>          ..
27.07.2016  15:09             1 209 somefile
               1 File(s)          1 209 bytes
               2 Dir(s)  125 137 285 120 bytes free

C:\>robocopy /IS x y somefile

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : tirsdag 25. september 2018 23:38:07
   Source : C:\x\
     Dest : C:\y\

    Files : somefile

  Options : /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30

------------------------------------------------------------------------------

                           1    C:\x\
100%        New File                1209        somefile

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         1         1         0         0         0         0
   Bytes :     1.1 k     1.1 k         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00


   Speed :             1209000 Bytes/sec.
   Speed :              69.179 MegaBytes/min.
   Ended : tirsdag 25. september 2018 23:38:07


C:\>robocopy /IS x y somefile

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : tirsdag 25. september 2018 23:38:13
   Source : C:\x\
     Dest : C:\y\

    Files : somefile

  Options : /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30

------------------------------------------------------------------------------

                           1    C:\x\
100%        Same                    1209        somefile

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         1         1         0         0         0         0
   Bytes :     1.1 k     1.1 k         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00


   Speed :             1209000 Bytes/sec.
   Speed :              69.179 MegaBytes/min.
   Ended : tirsdag 25. september 2018 23:38:13


C:\>robocopy /IS x y somefilex

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows
-------------------------------------------------------------------------------

  Started : tirsdag 25. september 2018 23:38:17
   Source : C:\x\
     Dest : C:\y\

    Files : somefilex

  Options : /DCOPY:DA /COPY:DAT /IS /R:1000000 /W:30

------------------------------------------------------------------------------

                           0    C:\x\

------------------------------------------------------------------------------

               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :         1         0         1         0         0         0
   Files :         0         0         0         0         0         0
   Bytes :         0         0         0         0         0         0
   Times :   0:00:00   0:00:00                       0:00:00   0:00:00
   Ended : tirsdag 25. september 2018 23:38:17


C:\>

I have encountered simular problems when building in Visual Studio. But I had to change the Build Dependencies and build order to solve it.

You could try to add a small delay in the post build, try adding like:

ping 127.0.0.1 -n 3 > nul

It will pause for 2 seconds before it continues...