Post Build exited with code 1

Visual Studio-2008Post Build

Visual Studio-2008 Problem Overview


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.

Visual Studio-2008 Solutions


Solution 1 - Visual Studio-2008

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

Solution 2 - Visual Studio-2008

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

Solution 3 - Visual Studio-2008

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.

Solution 4 - Visual Studio-2008

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!

Solution 5 - Visual Studio-2008

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

Solution 6 - Visual Studio-2008

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

Solution 7 - Visual Studio-2008

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

Solution 8 - Visual Studio-2008

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

Solution 9 - Visual Studio-2008

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.

Solution 10 - Visual Studio-2008

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.

Solution 11 - Visual Studio-2008

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

Solution 12 - Visual Studio-2008

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.

Solution 13 - Visual Studio-2008

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

Solution 14 - Visual Studio-2008

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

Solution 15 - Visual Studio-2008

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.

Solution 16 - Visual Studio-2008

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!

Solution 17 - Visual Studio-2008

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.

Solution 18 - Visual Studio-2008

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"

Solution 19 - Visual Studio-2008

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTim ScottView Question on Stackoverflow
Solution 1 - Visual Studio-2008Tim ScottView Answer on Stackoverflow
Solution 2 - Visual Studio-2008JanBorupView Answer on Stackoverflow
Solution 3 - Visual Studio-2008ValamasView Answer on Stackoverflow
Solution 4 - Visual Studio-2008ShaliniView Answer on Stackoverflow
Solution 5 - Visual Studio-2008AsherView Answer on Stackoverflow
Solution 6 - Visual Studio-2008wruckieView Answer on Stackoverflow
Solution 7 - Visual Studio-2008TechSavvySamView Answer on Stackoverflow
Solution 8 - Visual Studio-2008Bohdan KutsView Answer on Stackoverflow
Solution 9 - Visual Studio-2008jdurdenView Answer on Stackoverflow
Solution 10 - Visual Studio-2008DavidView Answer on Stackoverflow
Solution 11 - Visual Studio-2008AsherView Answer on Stackoverflow
Solution 12 - Visual Studio-2008Richard S.View Answer on Stackoverflow
Solution 13 - Visual Studio-2008firedflyView Answer on Stackoverflow
Solution 14 - Visual Studio-2008synedView Answer on Stackoverflow
Solution 15 - Visual Studio-2008TengizView Answer on Stackoverflow
Solution 16 - Visual Studio-2008golgothan3View Answer on Stackoverflow
Solution 17 - Visual Studio-2008RenniePetView Answer on Stackoverflow
Solution 18 - Visual Studio-2008CrazyTimView Answer on Stackoverflow
Solution 19 - Visual Studio-2008Roni AxelradView Answer on Stackoverflow