为什么Robocopy在构建过程中会跳过文件?

时间:2018-09-25 18:17:01

标签: robocopy visual-build-professional

我在C#项目的发布后事件中添加了robocopy文件。 X64 Release和Debug与X86 Debug一样可以很好地构建,但是X86 Release选项不会将Get-Parent-Device.exe文件复制到目标。

为什么?

注意:我总是可以仅添加一个步骤,并为该特定配置手动复制文件,这将“解决”我的问题,但是我想了解robocopy遇到了什么问题。源和目标很好,权限也很好,只是X86 / Release不起作用。

有趣的是,如果我右键单击解决方案并选择build,则robocopy可以在该配置上运行。如果我使用Visual Build Professional并生成项目的所有配置,那是行不通的。

这是log +文件:

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

以下是构建后事件的相关步骤:

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

这是构建步骤的屏幕截图。

Visual Build Pro steps

我看到了使用/ MIR的建议,但我不想镜像,只需复制该特定文件即可。可悲的是,/ log,/ log +和/ v没有提供非常详细的信息来说明为什么在这种特定情况下robocopy认为不需要复制文件。

我不喜欢在地毯下扫除问题或不了解技术问题,因此我不喜欢在这里发表文章。我担心的是,如果我不能依赖Robocopy,那么在Visual Studio中使用它可能是一个不好的选择。我需要可靠的副本,而不是不可靠的副本。

XCOPY试用版:

那没有用。到目前为止,最佳解决方案仍然是针对该特定配置的Visual Build Pro指令。 :-(

   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 个答案:

答案 0 :(得分:0)

Robocopy旨在仅复制更改的文件,但是您添加的/ IS选项假定可以复制任何您喜欢的文件。尝试添加参数/ IT(包括“已调整”的文件),但是以我的经验,它也不可靠。

此帖子How do I force Robocopy to overwrite files?证实了我的发现。他们的解决方案与我的解决方案相同:请使用 XCOPY

https://superuser.com/questions/314503/what-does-robocopy-mean-by-tweaked-lonely-and-extra/445137#445137表显示了robocopy如何对文件进行分组。

修改:
您收到的错误消息通常是源文件中的“文件不存在”。
由于XCOPY测试也失败了,所以我100%确信该文件不存在。
下面的例子:

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:\>

在Visual Studio中构建时遇到了类似的问题。但是我不得不更改构建依赖关系并建立构建顺序来解决它。

您可以尝试在发布时添加少量延迟,尝试添加如下内容:

ping 127.0.0.1 -n 3 > nul

它将暂停2秒钟,然后再继续...