Reputation: 3363
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?
Upvotes: 5
Views: 2623
Reputation: 1204
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.
Upvotes: 2
Reputation: 21418
%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
.
Upvotes: 2