构建后退出,代码为 1

发布于 2024-07-09 21:45:38 字数 262 浏览 9 评论 0原文

我有一个带有构建后事件的项目:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(20

几度春秋 2024-07-16 21:45:38

她的路径中的一个文件夹名称中有一个空格,并且周围没有引号。

She had a space in one of the folder names in her path, and no quotes around it.

我的痛♀有谁懂 2024-07-16 21:45:38

我为未来的访问者添加了此内容,因为这是一个相当活跃的问题。

ROBOCOPY 退出时显示“成功代码”,低于 8。请参阅:http://support.microsoft.com/kb/954404

这意味着:

robocopy exit code 0 = no files copied
robocopy exit code 1 = files copied
When the result is 1, this becomes an error exit code in visual studio.

所以我通过将其添加到底部轻松解决了这个问题批处理文件的

exit 0

建议以这种方式处理 ROBOCOPY 错误

rem each robocopy statement and then underneath have the error check.
if %ERRORLEVEL% GEQ 8 goto failed

rem end of batch file
GOTO success

:failed
rem do not pause as it will pause msbuild.
exit 1

:success
exit 0    

当没有文件被复制= 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:

robocopy exit code 0 = no files copied
robocopy exit code 1 = files copied
When the result is 1, this becomes an error exit code in visual studio.

So i solved this easily by adding this to the bottom of the batch file

exit 0

Suggest that handle ROBOCOPY errors in this fashion

rem each robocopy statement and then underneath have the error check.
if %ERRORLEVEL% GEQ 8 goto failed

rem end of batch file
GOTO success

:failed
rem do not pause as it will pause msbuild.
exit 1

:success
exit 0    

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.

埋葬我深情 2024-07-16 21:45:38

带有“Pings”的那个帮助了我......但可能会解释得更好一点......

对我来说,解决方案是改变:

copy $(TargetDir)$(TargetName).* $(SolutionDir)bin

对此(添加引号):

copy "$(TargetDir)$(TargetName).*" "$(SolutionDir)bin"

希望它对你有用。 :-)

The one with the "Pings" helped me... but may be explained a little better...

For me the solution was to change:

copy $(TargetDir)$(TargetName).* $(SolutionDir)bin

to this (adding quotes):

copy "$(TargetDir)$(TargetName).*" "$(SolutionDir)bin"

Hope it works for you. :-)

还在原地等你 2024-07-16 21:45:38

我使用代码 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!

深居我梦 2024-07-16 21:45:38

从 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

暮年慕年 2024-07-16 21:45:38

我必须以管理员身份运行 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

记忆で 2024-07-16 21:45:38

我遇到了类似的问题,但特别是在 Jenkins 构建环境中。 为了解决这个问题,我从在构建后事件中使用复制命令切换为使用复制目标。

我将这个: 更改

   <PropertyGroup>
      <PostBuildEvent>copy $(ProjectDir)bin\BLAH.Common.xml $(ProjectDir)App_Data\BLAH.Common.xml</PostBuildEvent>
   </PropertyGroup>

为:

  <Target Name="AfterBuild">
    <Copy SourceFiles="$(ProjectDir)bin\BLAH.Common.xml" DestinationFolder="$(ProjectDir)App_Data\" />
  </Target>

现在它工作正常。

我收到的具体错误是:

(PostBuildEvent target) -> 
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(4291,5): error MSB3073: The command "copy <http://1.2.3.4/job/BLAHv2/ws/Api/bin/BLAH.Common.xml> <http://1.2.3.4/job/BLAHv2/ws/Api/App_Data/BLAH.Common.xml"> exited with code 1. [<http://1.2.3.4/job/BLAHv2/ws/Api/Api.csproj]>

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:

   <PropertyGroup>
      <PostBuildEvent>copy $(ProjectDir)bin\BLAH.Common.xml $(ProjectDir)App_Data\BLAH.Common.xml</PostBuildEvent>
   </PropertyGroup>

to this:

  <Target Name="AfterBuild">
    <Copy SourceFiles="$(ProjectDir)bin\BLAH.Common.xml" DestinationFolder="$(ProjectDir)App_Data\" />
  </Target>

and it works fine now.

The specific error I was getting was:

(PostBuildEvent target) -> 
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(4291,5): error MSB3073: The command "copy <http://1.2.3.4/job/BLAHv2/ws/Api/bin/BLAH.Common.xml> <http://1.2.3.4/job/BLAHv2/ws/Api/App_Data/BLAH.Common.xml"> exited with code 1. [<http://1.2.3.4/job/BLAHv2/ws/Api/Api.csproj]>
憧憬巴黎街头的黎明 2024-07-16 21:45:38

对于那些在构建事件中使用“复制”命令的用户(预构建事件命令行或/和构建后事件命令行)来自项目 -> 属性:“复制”命令参数应如下所示:复制“文件源”“文件目标”。 请记住使用引号(以避免地址字符串中出现空格问题)。

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

跨年 2024-07-16 21:45:38

我能够通过以管理员身份运行 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.

苍风燃霜 2024-07-16 21:45:38

好吧,这个问题有很多解决方案,所以我只是发布我的解决方案,以便给人们更多提示。
我的情况是仔细检查路径中的文件夹,并确保它们全部存在于您的计算机中。 例如:“$(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.

海夕 2024-07-16 21:45:38

作为良好实践,我建议您将构建后事件替换为 MS Build文件复制任务

As a matter of good practice I suggest you replace the post build event with a MS Build File Copy task.

海未深 2024-07-16 21:45:38

对我来说,我必须确保我正在复制文件的程序当时没有运行。 语法上没有任何错误。 希望这对某人有帮助。

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.

赴月观长安 2024-07-16 21:45:38

我刚刚收到同样的错误。 我在目标路径中有一个需要转义的

c:\projects\%NotAnEnvironmentVariable%

%

c:\projects\%%NotAnEnvironmentVariable%%

I just received the same error. I had a % in the destination path that needed to be escaped

c:\projects\%NotAnEnvironmentVariable%

needed to be

c:\projects\%%NotAnEnvironmentVariable%%
慈悲佛祖 2024-07-16 21:45:38

对于那些在项目 -> 构建事件(预构建事件命令行或/和后构建事件命令行)中使用“复制”命令的人 属性:目标文件夹应该存在

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

菊凝晚露 2024-07-16 21:45:38

这么多的解决方案......

就我而言,我必须使用非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.

如此安好 2024-07-16 21:45:38

我也遇到了同样的问题,结果发现是因为我重命名了项目。 我进入项目属性并将程序集名称和根命名空间更改为项目名称,之后效果非常好!

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!

千紇 2024-07-16 21:45:38

还有另一个答案......

在我的例子中,我有一个针对 .Net Standard 1.3 和 .Net Framework 2.0 的 Visual Studio 2017 项目。 这是在 .csproj 文件中指定的,如下所示:

<TargetFrameworks>netstandard1.3;net20</TargetFrameworks>

我还有一个像这样的构建后事件命令行:

copy "E:\Yacks\YacksCore\YacksCore\bin\net20\Merlinia.YacksCore.dll" "E:\Merlinia\Trunk-Debug\Shared Bin\"

换句话说,我试图将构建生成的 .Net Framework .dll 复制到另一个位置。

当我进行重建时,由于此错误而失败:

MSB3073 The command "copy "E:\Yacks\YacksCore\YacksCore\bin\net20\Merlinia.YacksCore.dll" "E:\Merlinia\Trunk-Debug\Shared Bin\"" exited with code 1.

经过多次挫折后,我终于确定发生的情况是重建删除了所有输出文件,然后进行了 .Net Standard 1.3 的构建,然后尝试运行构建后事件命令行,由于要复制的文件尚未构建而失败。

因此,解决方案是更改构建顺序,即首先构建.Net Framework 2.0,然后构建.Net Standard 1.3。

<TargetFrameworks>net20;netstandard1.3</TargetFrameworks>

现在,这可以工作,但有一个小问题,即构建后事件命令行运行两次,因此文件被复制两次。

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:

<TargetFrameworks>netstandard1.3;net20</TargetFrameworks>

I also had a post-build event command line like this:

copy "E:\Yacks\YacksCore\YacksCore\bin\net20\Merlinia.YacksCore.dll" "E:\Merlinia\Trunk-Debug\Shared Bin\"

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:

MSB3073 The command "copy "E:\Yacks\YacksCore\YacksCore\bin\net20\Merlinia.YacksCore.dll" "E:\Merlinia\Trunk-Debug\Shared Bin\"" exited with code 1.

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.

<TargetFrameworks>net20;netstandard1.3</TargetFrameworks>

This now works, with the minor glitch that the post-build event command line is being run twice, so the file is copied twice.

作死小能手 2024-07-16 21:45:38

就我而言,在调用bat文件之前我必须cd(更改目录),因为bat文件内部是指定相对路径的复制操作。

:: Copy file
cd "$(ProjectDir)files\build_scripts\"
call "copy.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.

:: Copy file
cd "$(ProjectDir)files\build_scripts\"
call "copy.bat"
乖乖哒 2024-07-16 21:45:38

对我来说,原因是构建在构建输出文件夹(x86)上创建了一个平台文件夹,解决方案是将解决方案平台从“混合平台”更改为“任何 CPU”
在 VS

 VS 2019

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

VS 2019

夜血缘 2024-07-16 21:45:38

今年是 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 路径处理函数仍然仅使用反斜杠分隔符

(PathFindNextComponent 解析路径并返回该路径的一部分
第一个反斜杠之后的路径

)!

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 to copy /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

(PathFindNextComponent Parses a path and returns the portion of that
path that follows the first backslash

)!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文