none
MSBuild - error MSB3073: " exited with code -1.

    Question

  • I am trying to use a batch file in a make project in VS2010.

    The batch file launches various internal tools some of which are writing in Perl 5.8.8.

    I always see the 'exited with code -1' when the batch file build is successful.

    I added code to examine %errorlevel% and it returns 0 when MSBuild returns 'exited with code -1'.

    • So explicitly setting errorlevel does not help.
    • surrounding the batch file with setlocal and endlocal did not help.

    Where is the MSBuild environment getting the -1 value?

    1) How can I override this value so MSBuild does not display the error.

    BTW: the error always displays the entire contents of the 'Build Command Line' field which is lengthy in my case.

    2) How can I suppress this too?

    Thanks,

    J.R.

    Thursday, February 12, 2015 12:27 PM

All replies

  • Hello J.R.

    I'm trying to reproduce this issue so that I can unstand what is happening, what about share some more info here?

    1. What is make project here, please clarify it, do you mean the nmake in C++?
    https://msdn.microsoft.com/en-us/library/dd9y37ha.aspx

    2. What is that batch file and what is the relationship of that batch file and the project?

    3. The errorlevel seems different from %errorlevel%, do you have any environment about this? Why I say this is beacuase I saw this article:

    http://blogs.msdn.com/b/oldnewthing/archive/2008/09/26/8965755.aspx

    Since I'm not sure how you did this job, I think we may need to use logger to see if we can get some info:

    https://msdn.microsoft.com/en-us/library/ms171470.aspx

    Best regards,



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 13, 2015 6:32 AM
  • 1) I am referring to the Visual Studio's 'Makefile Project' type.

    2) This is the batch text I have in the 'Build command line' field.

    if "%VS71COMNTOOLS%"=="" goto NotInstalled
    if "%VCINSTALLDIR%"=="" call "%VS71COMNTOOLS%\vsvars32.bat"

    call .\make.bat "DEBUG_OPTS=/Zi /Od"
    if errorlevel 1 goto end

    goto end

    :NotInstalled
      echo Visual Studio .NET 2003 not installed
      goto end

    :end

    3) If I comment out calling the call to make.bat the VS does not display an error.

    The contents of the make.bat are very complicated and involve running perl scripts and the cl.exe to create perl binding into C code.

    Note that the errorlevel is tested after calling make.bat and it does not detect any error.

    Why would you thing the errorlevel test is different than %errorlevel%? Are you from Microsoft and know this for a fact? Either way the errorlevel test do not detect an error. I added test code after the errorlevel test and it was executed.

    I am having additional difficulties running msbuild from the command line to produce the log files.

    Note that this same configuration works with out issue in VS 2008. This became an issue when I converted the project to VS 2010.

    The make.bat does build fine with no errors. The issue is that VS 2010 (or msbuild) thinks it sees an error and I don't know why.

    Friday, February 13, 2015 8:27 AM
  • Hello J.R.

    I was thinking that you may haven't write errorlevel in the right way at that time(Or I think there is something related to the system environment), anyway its a wrong direction after I checked the msbuild ERRORLEVEL in detail and sorry for that. I'm new to here as a Backup for MSBuild forum.

    So MSBuild will returns 0 when success and 1 when failed. And the right way to write ERRORLEVEL can be checked from this forum post:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/82615310-3ac2-4265-87fb-c3d7a4e652fe/how-to-capture-error-code-in-command-line-with-msbuild?forum=msbuild

    Well, till now I haven't covered key point of this issue: your problem is "the calling of your bat file "make.bat " succeed in VS2008 but failed in VS2010 with error code -1." And in VS2008 msbuild is version 3.5 and in Visual Studio 2010 msbuild is in version 4.0, have you ever modified the toolsetting? https://msdn.microsoft.com/en-us/library/bb383985(v=vs.100).aspx

    What more, I searched everywhere and haven't find anyone else get this "-1" code. Do you have any more info about this error?

    Best regards,



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 13, 2015 11:22 AM
  • You need to post all the error message here. Only error MSB3073: " exited with code -1, without enough information to find the root of this issue.
    Friday, February 13, 2015 11:27 AM
  • OK Loser Dd, You asked for it.

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: The command "echo Build

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: if "%VS71COMNTOOLS%"=="" goto NotInstalled

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: echo VCINSTALLDIR=%VCINSTALLDIR%

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: if "%VCINSTALLDIR%"=="" call "%VS71COMNTOOLS%\vsvars32.bat"

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: call .\make.bat "DEBUG_OPTS=/Zi /Od"

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: if errorlevel 1 goto Simt4Failed

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: echo Copy to TCF agent

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: set AgentSimt4ApiDir=C:\Projects\tools\synaptics-tool-chain\Source\org.eclipse.tcf.agent\Simt4Api

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: set AgentToolbox=C:\Projects\tools\synaptics-tool-chain\Toolbox

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: if exist %AgentSimt4ApiDir% (

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   copy build\windows\simt4.dll %AgentSimt4ApiDir%

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   copy build\windows\simt4.lib %AgentSimt4ApiDir%

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   copy build\windows\simt4.dll %AgentToolbox%\windows\lib

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   copy build\windows\simt4.lib %AgentToolbox%\windows\lib

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   copy ISimt4Api.h %AgentSimt4ApiDir%

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   copy Simt4ApiLoader.h %AgentSimt4ApiDir%

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   copy Simt4ApiLoader.cpp %AgentSimt4ApiDir%

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   rem want to fully linked version

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   copy full-simt4.pl %AgentSimt4ApiDir%\simt4.pl

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   copy full-simt4.pl %AgentToolbox%\windows\bin\simt4.pl

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: )

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: goto end

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: :Simt4Failed

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   echo Simt4 Build Failed

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   goto end

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: :NotInstalled

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   echo Visual Studio .NET 2003 not installed

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:   goto end

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: :end

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073:

    1>C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Microsoft.MakeFile.Targets(38,5): error MSB3073: exit 0" exited with code -1.

    1>

    1>Build FAILED.

    1>

    1>Time Elapsed 00:00:10.00

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    I bet that was not helpful.

    Hmm ... you may have something there on the Toolset version.

    You may have noticed that the Build Command script specifically references the VS .NET 2003 version of vcvars32.bat. Perhaps that old choice of compiler is not playing nice with the version of MSBuild in VS 2010. I'll read up on the article you cited Barry.

    Saturday, February 14, 2015 5:09 PM
  • I tried manually editing the project files from <Project ToolsVersion="4.0"  to <Project ToolsVersion="3.5" to see what would happen.

    Unfortunately that resulted in a completely different error which I could not resolve despite trying solutions I found in other threads.

    Specifically the error

    1>C:\Projects\tools\simt4\simt4\simt4.2010.vcxproj(31,3): error MSB4019: The imported project "c:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.


    I am stuck again.
    Saturday, February 14, 2015 6:01 PM
  • You might note that I have an explicit

    exit 0

    at the end of my command script and MSBuild still reports return code -1.

    How is this even possible?

    Saturday, February 14, 2015 6:07 PM
  • @J.R,

    Based on the error message the problem is the whole command exit with error code -1. And that exit 0 seem located in your file, please check whether the whole command is like the following

    I've grouped your error message together:

    The command "echo Build
    
    echo VCINSTALLDIR=%VCINSTALLDIR%
    
    if "%VCINSTALLDIR%"=="" call "%VS71COMNTOOLS%\vsvars32.bat"
    
    call .\make.bat "DEBUG_OPTS=/Zi /Od"
    
    if errorlevel 1 goto Simt4Failed
    
    echo Copy to TCF agent
    
    set AgentSimt4ApiDir=C:\Projects\tools\synaptics-tool-chain\Source\org.eclipse.tcf.agent\Simt4Api
    
    set AgentToolbox=C:\Projects\tools\synaptics-tool-chain\Toolbox
    
    if exist %AgentSimt4ApiDir% (
    
    copy build\windows\simt4.dll %AgentSimt4ApiDir%
    
    copy build\windows\simt4.lib %AgentSimt4ApiDir%
    
    copy build\windows\simt4.dll %AgentToolbox%\windows\lib
    
    copy build\windows\simt4.lib %AgentToolbox%\windows\lib
    
    1copy ISimt4Api.h %AgentSimt4ApiDir%
    
    copy Simt4ApiLoader.h %AgentSimt4ApiDir%
    
    copy Simt4ApiLoader.cpp %AgentSimt4ApiDir%
    
    rem want to fully linked version
    
    copy full-simt4.pl %AgentSimt4ApiDir%\simt4.pl
    
    copy full-simt4.pl %AgentToolbox%\windows\bin\simt4.pl)
    
    goto end
    
    :Simt4Failed
    
    echo Simt4 Build Failed
    
     goto end
    
    error MSB3073: 
    
    error MSB3073: :NotInstalled
    
    echo Visual Studio .NET 2003 not installed
    
    goto end
    
    :end
    
    exit 0" 
    
    exited with code -1.

    So I think the problem is more related to how you run this batch in msbuild. The common step to work on this is like:

    http://www.danielfortunov.com/software/$daniel_fortunovs_adventures_in_software_development/2009/05/21/invoking_batch_files_from_msbuild

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Target Name="Default">
        <Exec Command="CALL batch.cmd" />
      </Target>
    </Project>

    What about let's check the following:

    1. What if you manually run your batch file within cmd?(Here I'm not so sure, I still haven't build a concept about your steps. I think msbuild is different from makefile project,see here http://blogs.msdn.com/b/vcblog/archive/2006/12/07/converting-to-msbuild.aspx and also here http://programmers.stackexchange.com/questions/216175/why-should-i-use-msbuild-instead-of-visual-studio-solution-files They seems to be different tool with different process.)

    2. What about check whether msbuild has executed your batch file in the right way? We need to make sure msbuild recognize this file.

    Best Regards,



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Sunday, February 15, 2015 2:46 AM
  • Hi Barry,

    1) You can see in what I have already provide I use the call command to run my make.bat file.

    2) Let me clarify the situation and my intent.

    2a) the make.bat is years old and was originally created to run using cmd.exe by someone else.

    2b) I use Visual Studio as my editor and debugger. Due to some legacy dependencies I cannot (yet) use a native .vcxproj to build this project. I am stuck with using my make.bat for now.

    2c) For convenience I have been using a 'Make file' project type to launch the make.bat. This has the advantage of parsing the errors messages from cl and being able to start the debugger after the build succeeds. This has been successful with Visual Studio 2008.

    I have a related project which I am building with Visual Studio 2010. I thought it would be more convenient to use Visual Studio 2010 for both. So it is Visual Studio 2010 specifically which outputs the MSB3073 error message. The error repeats many lines which results in the output from my make.bat inconveniently scrolling out of view.

    So it seems that MSBuild is processing the .vcproj file in Visual Studio 2010.

    2d) Why I posted this message is due to Visual Studio 2010 reporting the MSB3073 error when my make.bat is successful.

    3) As the first article that you referenced suggests, I tried the /B switch of the exit command. It made NO difference in the resulting output.

    4) My make.bat file via Visual Studio 2010 is properly being executed because I can see the successful results of the compiles and link.

    Sunday, February 15, 2015 3:48 PM
  • @J.R,
    Thanks for your detailed description and I want to share something in my mind:
    First, all the things we have:
    Now I can unstand that you want to use MSBuild to build your project which is written as make.bat file. And as we can see from your previous message that the whole bat file is translated to MSBuild command. But the result is that MSBuild does not know that complex command and at last it reports -1 to you.  
    VS2008:
    You mentioned "This has been successful with Visual Studio 2008." and I agree it will work because make can recognize many "built-in" DOS commands, it can also use bat file in it.
    VS2010:
    VS2010 is different, it switch to use MSBuild instead of previous things.
    As a result, when we use MSBuild it is already a different experience:
    Here we start https://msdn.microsoft.com/en-us/library/dd393574.aspx
    And here is the common command:
    MSBuild.exe MyProj.proj /property:Configuration=Debug
    The problem is how MSBuild can run a bat file? I know you have called "make.bat" in your batch. However it is not MSBuild way. MSBuild need at least a project file, like the way mentioned here:
    https://msdn.microsoft.com/en-us/library/dd576348.aspx

    When I asked you to use "call" before, actually I mean I want you to add your bat file in your project file, I don't know you do not have any vcxproj file. 

    I hope I've already clarified our case without error, please correct me if I'm wrong any where.

    Furthermore, I think it is better for you to consider use MSBuild to create a new MSBuild script. They are different ways when building the application in my mind.

    Best regards,



    Barry
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 16, 2015 9:49 AM
  • I'm getting the same thing with an nmake project that was converted from VS2005 to VS2015.

    The project's nmake command-line is essentially this:

    nmake -d -f Makefile rebuild ^
    SOMEVAR="some value" ^
    ANOTHERVAR="another value" ^
    ...
    MANYMORE="30 or so values passed to nmake"

    Doing a rebuild always fails, as does a clean+build since that's the 2 step version of what rebuild does. The only difference between the commands for the 3 actions is the target name given on the command line. Oddly enough, a subsequent build succeeds as far as VS2015/MSBuild is concerned, which tells me it's not related to the command-line length.

    I always get:

    error MSB3073: The command "nmake -d -f Makefile rebuild ..." exited with code -1.

    Wednesday, July 8, 2015 7:06 PM
  • I am having the same trouble with Visual Studio 2010 through 2015.  My NMAKE project "Build Command Line" entry is "go.bat".  I can put anything in that batch file and things work as expected, error codes are returned, and when ERRORLEVEL is 0 I see:

    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

    However, if I run make.exe from within the batch file, no matter the outcome (even if ERRORLEVEL == 0) I see this:

    1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3073: The command "call go.bat" exited with code -1.
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    I have tried "EXIT /b 0" and "EXIT 0", it doesn't matter, I still get the same error.

    Any ideas?

    Regards,

    Justin

    Not sure if it matters, but this is the version of make:

    GNU Make version 3.78.1, by Richard Stallman and Roland McGrath.
    Built for Windows32

    Just for fun I also tried GNU Make 3.81, no change in behavior.



    Monday, August 24, 2015 2:44 AM

  • Solution:

    I finally realized MSBUILD was parsing the console output.  

    I added this to my batch file to confirm:

    echo ERROR: some error happened

    MSBUILD then reported the failure.  It should be noted that ERRORLEVEL takes precedence if non 0.

    -Justin 

    PS Once you know what the problem is, googling it is easy:

    http://blogs.msdn.com/b/msbuild/archive/2006/11/03/msbuild-visual-studio-aware-error-messages-and-message-formats.aspx


    Tuesday, August 25, 2015 1:46 AM