Post Build exited with code 1

馋奶兔 提交于 2020-02-10 05:05:05

问题


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.


回答1:


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




回答2:


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:

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

Hope it works for you. :-)




回答3:


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!




回答4:


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.




回答5:


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




回答6:


I had to run VS as Administrator to get my post-build copy to an OS protected "..\Common7\IDE\PrivateAssemblies" to work




回答7:


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




回答8:


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]>



回答9:


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.




回答10:


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




回答11:


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.




回答12:


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%%



回答13:


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.




回答14:


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




回答15:


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.




回答16:


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!




回答17:


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.




回答18:


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"


来源:https://stackoverflow.com/questions/310126/post-build-exited-with-code-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!