Post Build exited with code 1

后端 未结 18 1851
囚心锁ツ
囚心锁ツ 2020-12-04 16:11

I have a project with a post build event:

copy $(ProjectDir)DbVerse\\Lunaverse.DbVerse.*.exe  $(TargetDir)

It works fine every time on my m

相关标签:
18条回答
  • 2020-12-04 16:30

    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.

    0 讨论(0)
  • 2020-12-04 16:30

    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!

    0 讨论(0)
  • 2020-12-04 16:32

    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]>
    
    0 讨论(0)
  • 2020-12-04 16:34

    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.

    0 讨论(0)
  • 2020-12-04 16:37

    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.

    0 讨论(0)
  • 2020-12-04 16:37

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

    0 讨论(0)
提交回复
热议问题