构建后退出,代码为 1
我有一个带有构建后事件的项目:
copy $(ProjectDir)DbVerse\Lunaverse.DbVerse.*.exe $(TargetDir)
每次在我的机器上都运行良好。 我有一个新开发人员,他总是收到“退出代码 1”错误。 我让她在 DOS 提示符下运行相同的命令,效果很好。 可能是什么原因造成的? 有什么办法可以找出真正的错误吗?
我们都使用 Visual Studio 2008。
I have a project with a post build event:
copy $(ProjectDir)DbVerse\Lunaverse.DbVerse.*.exe $(TargetDir)
It works fine every time on my machine. I have a new developer who always gets the "exited with code 1" error. I had her run the same command in a DOS prompt, and it worked fine. What could be causing this? Is there any way to get to the real error?
We are both using Visual Studio 2008.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(20)
她的路径中的一个文件夹名称中有一个空格,并且周围没有引号。
She had a space in one of the folder names in her path, and no quotes around it.
我为未来的访问者添加了此内容,因为这是一个相当活跃的问题。
ROBOCOPY 退出时显示“成功代码”,低于 8。请参阅:http://support.microsoft.com/kb/954404
这意味着:
所以我通过将其添加到底部轻松解决了这个问题批处理文件的
建议以这种方式处理 ROBOCOPY 错误
当没有文件被复制= VS 中没有错误时,将会出现混乱。 然后,当发生更改时,文件确实会被复制,VS 会出现错误,但开发人员想要的一切都已完成。
其他提示:不要在脚本中使用暂停,因为这将成为 VS 构建中的无限期暂停。 在开发脚本时,请使用诸如
timeout 10
之类的内容。 您会注意到这一点并将其注释掉,而不是进行悬挂构建。I have added this for future visitors since this is quite an active question.
ROBOCOPY exits with "success codes" which are under 8. See: http://support.microsoft.com/kb/954404
This means that:
So i solved this easily by adding this to the bottom of the batch file
Suggest that handle ROBOCOPY errors in this fashion
Confusion will set in when no files are copied = no error in VS. Then when there are changes, files do get copied, VS errors but everything the developer wanted was done.
Additional Tip: Do not use a pause in the script as this would become an indefinite pause in the VS build. while developing the script, use something like
timeout 10
. You will notice this and comment it out rather than have a hanging build.带有“Pings”的那个帮助了我......但可能会解释得更好一点......
对我来说,解决方案是改变:
对此(添加引号):
希望它对你有用。 :-)
The one with the "Pings" helped me... but may be explained a little better...
For me the solution was to change:
to this (adding quotes):
Hope it works for you. :-)
我使用代码 1 的原因是目标文件夹是只读的。 希望这对某人有帮助!
我有一个构建后事件,将一个目录复制到另一个目录,并且目标是只读的。 所以我只是取消选中目录及其所有子目录的只读属性! 只要确保它是一个安全的目录即可!
My reason for the Code 1 was that the target folder was read only. Hope this helps someone!
I had a post build event to do a copy from one directory to another and the destination was read only. So I just went and unchecked the read-only attribute on the directory and all its subdirectories! Just make sure that its a directory that's safe to do so!
从 SysInternals 获取进程监视器
将其设置为监视 Lunaverse.DbVerse(在 Path 字段上)查看操作结果。
从那里应该很明显出了什么问题
Get process monitor from SysInternals
set it up to watch for the Lunaverse.DbVerse (on the Path field) look at the operation result.
It should be obvious from there what went wrong
我必须以管理员身份运行 VS 才能将构建后副本复制到受操作系统保护的“..\Common7\IDE\PrivateAssemblies”才能工作
I had to run VS as Administrator to get my post-build copy to an OS protected "..\Common7\IDE\PrivateAssemblies" to work
我遇到了类似的问题,但特别是在 Jenkins 构建环境中。 为了解决这个问题,我从在构建后事件中使用复制命令切换为使用复制目标。
我将这个: 更改
为:
现在它工作正常。
我收到的具体错误是:
I had a similar issue but specifically in a Jenkins build environment. To fix the issue, I switched from using a copy command in the post build event to using a copy target.
I changed this:
to this:
and it works fine now.
The specific error I was getting was:
对于那些在构建事件中使用“复制”命令的用户(预构建事件命令行或/和构建后事件命令行)来自项目 -> 属性:“复制”命令参数应如下所示:
复制“文件源”“文件目标”
。 请记住使用引号(以避免地址字符串中出现空格问题)。For those, who use 'copy' command in Build Events (Pre-build event command line or/and Post-build event command line) from Project -> Properties: you 'copy' command parameters should look like here:
copy "source of files" "destination for files"
. Remember to use quotation marks (to avoid problems with spaces in strings of address).我能够通过以管理员身份运行 Visual Studio 来修复我的代码 1。 显然,没有管理员权限,它无法执行 shell 命令。
I was able to fix my Code 1 by running Visual Studio as Admin. Apparently it didn't have access to execute the shell commands without Admin.
好吧,这个问题有很多解决方案,所以我只是发布我的解决方案,以便给人们更多提示。
我的情况是仔细检查路径中的文件夹,并确保它们全部存在于您的计算机中。 例如:“$(SolutionDir)\partBin\Bin\$(ProjectName).pdb”,但“Bin”不在partBin文件夹中。
Ok, this is a problem with many solutions, so I just post mine to give people more hints.
My situation is to double check the folders in your path and make sure all of them exist in your machine. For example: "$(SolutionDir)\partBin\Bin\$(ProjectName).pdb", but "Bin" is not in partBin folder.
作为良好实践,我建议您将构建后事件替换为 MS Build文件复制任务。
As a matter of good practice I suggest you replace the post build event with a MS Build File Copy task.
对我来说,我必须确保我正在复制文件的程序当时没有运行。 语法上没有任何错误。 希望这对某人有帮助。
For me I had to make sure the the program I was coping file to was not running at the time. There weren't any errors in the syntax. Hope this helps someone.
我刚刚收到同样的错误。 我在目标路径中有一个需要转义的
%
I just received the same error. I had a % in the destination path that needed to be escaped
needed to be
对于那些在项目 -> 构建事件(预构建事件命令行或/和后构建事件命令行)中使用“复制”命令的人 属性:目标文件夹应该存在
For those, who use 'copy' command in Build Events (Pre-build event command line or/and Post-build event command line) from Project -> Properties: target folder should exist
这么多的解决方案......
就我而言,我必须使用非unicode(西方,Windows)编码保存bat文件。 默认情况下,当我将文件添加到 Visual Studio 时(可能我应该在 VS 之外完成),它添加了 UTF-8 编码。
So many solutions...
In my case, I had to save the bat file with non-unicode (Western, Windows) encoding. By default when I added the file to visual studio (and probably I should have done it outside of the VS), it added with UTF-8 encoding.
我也遇到了同样的问题,结果发现是因为我重命名了项目。 我进入项目属性并将程序集名称和根命名空间更改为项目名称,之后效果非常好!
I had this same issue and it turned out that it was because I had renamed the project. I went into the project properties and changed the Assembly Name and Root Namespace to the project name and it worked great after that!
还有另一个答案......
在我的例子中,我有一个针对 .Net Standard 1.3 和 .Net Framework 2.0 的 Visual Studio 2017 项目。 这是在 .csproj 文件中指定的,如下所示:
我还有一个像这样的构建后事件命令行:
换句话说,我试图将构建生成的 .Net Framework .dll 复制到另一个位置。
当我进行重建时,由于此错误而失败:
经过多次挫折后,我终于确定发生的情况是重建删除了所有输出文件,然后进行了 .Net Standard 1.3 的构建,然后尝试运行构建后事件命令行,由于要复制的文件尚未构建而失败。
因此,解决方案是更改构建顺序,即首先构建.Net Framework 2.0,然后构建.Net Standard 1.3。
现在,这可以工作,但有一个小问题,即构建后事件命令行运行两次,因此文件被复制两次。
Yet another answer ...
In my case I had a Visual Studio 2017 project targeting both .Net Standard 1.3 and .Net Framework 2.0. This was specified in the .csproj file like this:
I also had a post-build event command line like this:
In other words I was trying to copy the .Net Framework .dll produced by the build to an alternative location.
This was failing with this error when I did a Rebuild:
After much frustration I finally determined that what was happening was that Rebuild deleted all of the output files, then did the build for .Net Standard 1.3, then tried to run the post-build event command line, which failed because the file to be copied wasn't built yet.
So the solution was to change the order of building, i.e., build for .Net Framework 2.0 first, then for .Net Standard 1.3.
This now works, with the minor glitch that the post-build event command line is being run twice, so the file is copied twice.
就我而言,在调用bat文件之前我必须
cd
(更改目录),因为bat文件内部是指定相对路径的复制操作。In my case I had to
cd
(change directory) before calling the bat file, because inside the bat file was a copy operation that specified relative paths.对我来说,原因是构建在构建输出文件夹(x86)上创建了一个平台文件夹,解决方案是将解决方案平台从“混合平台”更改为“任何 CPU”
在 VS
For me, the reason was that the build created a platform folder on the build output folder (x86), and the fix was to change the solution platform from 'Mixed Platforms' to 'Any CPU'
in VS
今年是 2023 年,我使用 VS2022,很幸运地遇到了 Error MSB3073 The command "copy /Y "C:/vcpkg/installed/x64-windows/bin/cairo-2.dll" C:\Users\ User\source\x64\Debug:VCEnd" 退出,代码为 1。PostBuild 事件字段的内容为
copy /Y "C:/vcpkg/installed/x64-windows/bin/cairo-2。 dll”$(TargetDir)
,罪魁祸首不是文件夹名称中的空格,而是我在复制源文件参数中使用的目录分隔符“/”。 当我将 PostBuild 事件字段内容更改为copy /Y "C:\vcpkg\installed\x64-windows\bin\cairo-2.dll" $(TargetDir)
时,错误 MSB3073 为消失了,项目已成功构建。 Windows API 函数中使用的路径名中渗透正斜杠放松了开发人员的警惕性,但 shell 路径处理函数仍然仅使用反斜杠分隔符)!
This is the year of 2023, I use VS2022, and been lucky to bump into Error MSB3073 The command "copy /Y "C:/vcpkg/installed/x64-windows/bin/cairo-2.dll" C:\Users\User\source<projectName>\x64\Debug:VCEnd" exited with code 1. The PostBuild event field had a content of
copy /Y "C:/vcpkg/installed/x64-windows/bin/cairo-2.dll" $(TargetDir)
, and the culprit was not a space in the folder names but the directory separator character '/' I used in the copy source file parameter. As soon as I changed the PostBuild event field content tocopy /Y "C:\vcpkg\installed\x64-windows\bin\cairo-2.dll" $(TargetDir)
, the error MSB3073 was gone and the project has built successfully. The penetration of forward slashes into path names used in Windows API functions relaxes developer's alertness, but shell path handling functions still use only a backslash director separator)!