5

Any command line application return code as exit codes that notify the host environment the final status of the instruction. VS command line: devenv.com return number of codes. Although there is no (or I can't find any) such list or post regarding this. Is there any documentation? If not, anyone from VS team can document this here?

1
  • devenv does set the errorlevel to nonzero when any project in the solution fails to compile; it might depend on devenv command line supplied parameters and switches. Please edit your question and provide a minimal reproducible example of a typical devenv command line and failing output.
    – JosefZ
    Oct 23, 2017 at 13:43

2 Answers 2

2

%errorlevel% (cmd.exe) or $LASTEXITCODE (Powershell) will be set to 0 on success, any other value suggests a failure for msbuild.exe or devenv.exe.

1
  • Ugh I wish there was decent documentation for this. Our build literally outputs all builds succeeded, 0 failed yet devenv.com returns 1. Surely there is a way to find why devenv.com is throwing an error?
    – Shiv
    Jul 4, 2022 at 4:35
2

In Visual Studio 2019 build 16.11.2, I found that performing a build with devenv.exe always sets the ERRORLEVEL to 0, while building with devenv.com sets ERRORLEVEL to a positive number if the build fails, or 0 if it succeeds. devenv.com also waits for the build to finish before returning control to the shell. Both devenv.com and devenv.exe support the /Out parameter for specifying a log file explicitly. In addition, devenv.com generates console output which can be redirected to nul if not required.

So, running builds via a Windows batch file, you can run devenv.com, then immediately check for failure:

"C:\path\to\devenv.com" "my-solution.sln" /Rebuild "Release|x64" /Out "my-solution-build.log" > nul
if ERRORLEVEL 1 echo Error %ERRORLEVEL% building my-solution.sln & goto my-failed-build-label
echo Build succeeded
. . .

In the above example, the test if ERRORLEVEL 1 will be true if ERRORLEVEL is set to 1 or higher.

It is possible for post-build events within each project to encounter error conditions and to set an ERRORLEVEL, for example:

rem This is in a post-build event for a project
if not exist "path-to-expected-build-output.exe" exit /b 3

When devenv.com exits, these post-build ERRORLEVELs may get swallowed up and converted to an ERRORLEVEL such as 1.

1
  • We get error code 0 on success in devenv.com in vs2022 and earlier. 1 (non zero) is conventionally an error code not success.
    – Shiv
    May 19, 2022 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.