在预构建事件中执行批处理文件时出现问题 [英] Problem Executing Batch File in Pre-Build Event
问题描述
我正在尝试在预构建事件期间执行批处理文件.我有一个新项目,并在其中添加了 foo.bat.该文件包含以下行:
I'm trying to execute a batch file during a pre-build event. I have a new project and have added foo.bat to it. The file contains the following line:
echo bar
当我将预构建事件命令行设置为 foo.bat 时,出现以下错误:
When I set the pre-build event command line to foo.bat, I get the following error:
命令foo.bat"退出,代码为 9009.
The command "foo.bat" exited with code 9009.
当我将预构建事件命令行设置为调用 foo.bat 时,出现以下错误:
When I set the pre-build event command line to call foo.bat, I get the following error:
call foo.bat"命令退出,代码为 1.
The command "call foo.bat" exited with code 1.
我读到的与这些代码相关的所有内容通常都表明批处理文件的内容存在问题(在这种情况下不太可能)或系统找不到批处理文件.
Everything I've read related to those codes generally indicates that there is a problem with the contents of the batch file (not likely in this case) or that the system cannot find the batch file.
批处理文件在命令提示符下工作正常.我已经尝试过的事情:使用不同的工具、各种编码创建文件、在文件中放置 exit 0、文件的不同构建操作以及将文件复制到输出目录.一切都没有运气.
The batch file works fine from a command prompt. Things I've tried already: Created the file using different tools, various encodings, placing exit 0 in the file, different build actions for the file, and copying the file to the output directory. All with no luck.
我错过了什么?它必须是一些简单的东西.
What am I missing? It has to be something simple.
更新: 是的,这很简单 - 路径的长度太长了.有关详细信息,请参阅下面的答案.
Update: Yep, it was simple - the length of the path was too long. See answer below for details.
谢谢!
推荐答案
看起来我的问题是批处理文件的路径长度.由于这是一个概念证明,我让 VS 在默认位置创建它:
It looks like my problem was the length of the path to the batch file. As this was a proof of concept I let VS create it in the default location:
C:\Documents 和设置\用户XXX\我的文档\Visual Studio2010\Projects\SolutionXXX\ProjectXXX\foo.bat
C:\Documents and Settings\UserXXX\My Documents\Visual Studio 2010\Projects\SolutionXXX\ProjectXXX\foo.bat
一旦我将解决方案移动到路径较短的位置,它就可以正常工作.=P
As soon as I moved the solution to a location with a shorter path it worked fine. =P
感谢您的建议!
这篇关于在预构建事件中执行批处理文件时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!