Visual Studio中xcopy命令以代码9009退出

4
当我使用10个项目构建我的解决方案时,有7个项目构建失败。所有10个项目都有后置构建事件。即使那些使用xcopy命令的项目也是如此。我之所以这样说是因为我的同事认为VS 2012和xcopy并不好用...
这7个构建失败之前没有发生过。
当我尝试构建项目或“偶尔”启动Visual Studio时,会出现以下错误:
我收到了这个错误:
Error   1   The command "xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\Client" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\Client\" /s /e /v
xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\Content" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\Content\" /s /e /v
xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\Views" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\Views\" /s /e /v

xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\web.config" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\"
xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\global.asax" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\"

xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\Tools" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\..\Tools\" /s /e /v
" exited with code 9009.    Swan.Replaced.Mobile.Web

我在SO上搜索了很多,发现这个问题的主要原因似乎是:
1.) A whitespace in the path/folder name
2.) The command does not get full paths
3.) Maybe some environment/system variables problem?

我在后期构建事件中没有看到这个错误:

xcopy /y "$(ProjectDir)Client" "$(TargetDir)..\Client\" /s /e /v
xcopy /y "$(ProjectDir)Content" "$(TargetDir)..\Content\" /s /e /v
xcopy /y "$(ProjectDir)Views" "$(TargetDir)..\Views\" /s /e /v
xcopy /y "$(ProjectDir)web.config" "$(TargetDir)..\"
xcopy /y "$(ProjectDir)global.asax" "$(TargetDir)..\"
xcopy /y "$(ProjectDir)Tools" "$(TargetDir)..\..\Tools\" /s /e /v

我的目标目录是这个输出路径:

..\build\web\bin\

我的项目目录是这样的:

D:\Replaced\branches\ReplacedTest

注释:当我在控制台窗口使用xcopy时,完全没有问题。

这是我的配置:

  • Windows 7(64位)
  • Visual Studio 2012 Premium

我尝试过以下方法来解决问题:

  • 重新构建解决方案
  • 清理解决方案
  • 清除输出路径数据
  • 重新启动计算机
  • 咬桌面

什么都没用 :/

有人可以帮忙找出错误吗?谢谢!


2个回答

5

xcopy通常位于C:\Windows\system32,因此为了使VS看到xcopy,这个路径应该在您的PATH环境变量中。您可以通过运行以下命令来检查:

echo %path%

在命令行中,您应该看到xcopy路径与其他文件夹并排...

3
我刚刚在xcopy命令前添加了C:\Windows\System32\,问题得到了解决。同时,请检查是否意外添加了其他的换行符。但如果您愿意,也可以将系统目录添加回到Windows路径中。您可以在“计算机 - 属性 - 高级系统设置 - 环境变量 - 系统变量 - 路径”中找到它。
例如:
C:\Windows\System32\xcopy /s /y "$(ProjectDir)bin\ken.MojoPortal.HtmlTools.Web.dll" "$(SolutionDir)Web\bin\"

P.S. 原文发表在这里:https://ict.ken.be/xcopy-exit-with-code-9009-in-visual-studio-post-build

此处讨论的是在Visual Studio的后置生成事件中使用XCOPY时可能会遇到的错误代码9009。该错误通常表示找不到要复制的文件或命令。解决此问题的方法之一是确保指定了正确的文件路径和命令。如果您正在使用相对路径,请确保它们相对于正确的目录。

你也可以用%SYSTEMROOT%替换C:\Windows路径。 - d.i.joe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接