1

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                              
     -------------------------------------------------------------------------------
Sarah Weinberger
  • 15,041
  • 25
  • 83
  • 130
  • perhaps that file is the exactly the same? – Daniel A. White Sep 25 '18 at 18:19
  • @DanielA.White ? All I care is that the file is there. The file does NOT copy over. The x86/Release folder is empty. I had to add a copy after the build to place the file there. From what I see, not having read the proposed answer, is that Microsoft needs to delete Robocopy and replace the utility. – Sarah Weinberger Sep 25 '18 at 20:56

1 Answers1

0

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...

Large
  • 587
  • 4
  • 16
  • But the file is not changed, tweaked, or otherwise. I delete the entire contents of the `x86/Release` folder, as you can see. I then `Build` the solution. Visual Studio along with the `Post-Build Event` is supposed to create the contents. Part of that is Robocopy taking the file from the redistribution folder and copying that to the release directory. That does not happen. There is NO override, as it does not exist at the destination. – Sarah Weinberger Sep 25 '18 at 20:58
  • Xcopy copied to every other configuration, just not `x86/Release`. The VB Pro command, however, works flawlessly. So far the best solution, only solution, is my hack. – Sarah Weinberger Sep 25 '18 at 21:14
  • I think I know that is happening. After testing robocopy with same parameters as you, the status is stated: 1 C:\slettes\ 100% Same 854072 putty.exe Now if change the filename I want to copy to something that does not exists, then it shows: 0 C:\slettes\ So the reason for this weird feedback is that file "Get-Parent-Device.exe" does not exists in source when robocopy is executed. Check your projects build order, you might need to change it there. – Large Sep 25 '18 at 21:24
  • Status from putty? 854072? There is no "same". Really, there is no "same," whatever that is. I have 4 configurations x64/x86 Release/Debug. When Xcopy/Robocopy get to the 4th build, the copy does not go through, even though the file is not there. X86/Release is the 4th in the list. Building on my Samsung 850 Pro SSD takes a minute or so. Maybe Robocopy/Xcopy does not like copying the same file to different folders multiple times within a couple of minutes and complains at the 4th? Too much thinking, if that is the case. Copy means copy. Period, no thinking required. – Sarah Weinberger Sep 25 '18 at 21:29
  • I just wanted to illustrate that you get the same feedback from robocopy, let me update the answer to clarify... – Large Sep 25 '18 at 21:34
  • Do you have RAPID mode enable for your Samsung 850 in the Samsung Magician tool? https://cdn-reichelt.de/documents/datenblatt/E600/MZ-75EXXXB_DB.pdf - My laptop did some odd things while that was activated, files appearing later than normal and so on. Could be worth a shot to check out. – Large Sep 25 '18 at 22:30
  • "Get-Parent-Device.exe" is a static always existing file in my redistribution folder. I use Robocopy to copy a version to the target directory. As such, the file always exists, never not exists. The build order is fine. The Robocopy call executes in the Post-Build Event of the final executable. I should add after all 3 other configurations. Something else is afoot. – Sarah Weinberger Sep 25 '18 at 22:37
  • Nope. The Samsung Magician interface looks pretty slick. Samsung updated the look, since the last time that I saw it. Thanks for mentioning the Rapid feature. I never heard of it before. – Sarah Weinberger Sep 25 '18 at 23:06
  • 1
    ping made no difference. By the way, VB Pro always works. The file definitely exists. This bug may be one that just is, as there is a workaround. I was just thinking that other developers, and me, might want to know why Microsoft commands do not always perform as expected. – Sarah Weinberger Sep 25 '18 at 23:13