xcopy 以代码 4 退出,如何解决这个问题?

xcopy exited with code 4, how to get this resolved?

我正在 运行从 Team Foundation Server(TFS) 构建,但构建失败并出现错误

    "xcopy "C:\eComObjects_MP10\Microsoft\DynamicsCrm" 
    "D:\Builds\Unicorn\MaintPackage10- Daily\Sources\MaintPackage10\WebInterface\Store\Inetpub\wwwroot\Bin\DynamicsCrm" 
    /E /Y /I " exited with code 4".

当我简单地转到命令提示符和 运行 上面的命令时,它失败了,但是当这个命令是 运行 删除 /E/Y/I 和末尾的双引号后,它在命令提示符下工作正常。这里可能有什么问题?

由于它也失败并出现命令提示符,因此它与 TFS 构建无关。

Xcopy exit code 4 means "Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line."

这有多种原因。在您的情况下,这可能是由于源和目标(路径长度)的 length。生成的路径名超过了最大允许长度。这可能是由于 /e 选项 /e : Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options. Xcopy command 引用。

更多的方法可以参考下面类似的问题:

  • What is going wrong when Visual Studio tells me "xcopy exited with code 4"
  • Command copy exited with code 4 when building - Visual Studio restart solves it

除了磁盘 space 或命令行语法错误的可能性外,这也可能是由于权限(可能还有其他原因?)

我建议打开命令提示符和 copy/paste 有问题的 XCOPY 命令,这样您就可以看到实际发生的错误。就我而言,是 "Access Denied" 提示我检查我发现我的用户帐户没有适当访问权限的目标文件夹。