I'm trying to build a solution through visual studio command prompt. I'm using VS 2012. I've written a script and I use it through VS command prompt. The script content is:
set BUILD_STATUS=%ERRORLEVEL%
msbuild C:\MyProj.vcxproj /p:Configuration=Debug /p:platform=x64 /verbosity:minimal
#if %BUILD_STATUS%==1 goto fail
:fail
exit /B 1
If the solution is already compiled and it is up-to-date, then the error is returned and execution is terminating. The execution moves to :fail block directly without executing further lines. This happens only when solution is up-to-date, but out-of-date solutions work fine.
I tried the negation as well:
#if not %BUILD_STATUS%==0 goto fail
Please help.
ERRORLEVEL is not an environment variable as you're trying to capture it. Rewrite your batch as:
msbuild C:\MyProj.vcxproj /p:Configuration=Debug /p:platform=x64 /verbosity:minimal
#if ERRORLEVEL 1 goto fail
rem If no error, success
goto success
:fail
exit /B 1
:success
exit /B 0
Related
I've installed Visual 2017 C++ build tools. I am attempting to run vsdevcmd to prepare the environment. But, I am getting an error stating VC++ tools are not installed when they infact are.
Below is the error I am getting:
[DEBUG:vcvars.bat] Could not find VC++ tools version "14.16.27023" under "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\".
[DEBUG:ext\vcvars.bat] init:COMPLETE
[DEBUG:core\vsdevcmd_end] initializing with arguments ''
[ERROR:VsDevCmd.bat] *** VsDevCmd.bat encountered errors. Environment may be incomplete and/or incorrect. ***
[ERROR:VsDevCmd.bat] In an uninitialized command prompt, please 'set VSCMD_DEBUG=[value]' and then re-run
[ERROR:VsDevCmd.bat] vsdevcmd.bat [args] for additional details.
[ERROR:VsDevCmd.bat] Where [value] is:
[ERROR:VsDevCmd.bat] 1 : basic debug logging
[ERROR:VsDevCmd.bat] 2 : detailed debug logging
[ERROR:VsDevCmd.bat] 3 : trace level logging. Redirection of output to a file when using this level is recommended.
[ERROR:VsDevCmd.bat] Example: set VSCMD_DEBUG=3
[ERROR:VsDevCmd.bat] vsdevcmd.bat > vsdevcmd.trace.txt 2>&1
[DEBUG:VsDevCmd] Writing post-execution environment to C:\Users\KRAFTW~1\AppData\Local\Temp\dd_vsdevcmd15_env.log
[DEBUG:VsDevCmd.bat] --------------------- VS Developer Command Prompt Environment [post-init] ---------------------
Here's the level 3 error reporting of that specific error:
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC>if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\" (
set "VCToolsInstallDir=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\"
set "VCToolsVersion=14.16.27023"
) else (
set VCToolsInstallDir=
if "3" GEQ "2"
goto :end
)
[DEBUG:vcvars.bat] Could not find VC++ tools version "14.16.27023" under "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\".
That directory exists because I copied and pasted the path and was able to change into that directory. Using explorer I can also see that exact version does exist, and within it all the expected tools (as can be seen in the image below)
Any ideas what the problem could be?
Edit
As Hans pointed out in the comment there is wild character at the beginning of the filename 14.16.27023.
According to the output it's loading the path from here: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC>set "__VCVARS_DEFAULT_CONFIG_FILE=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
I've inspected this file and it contains the following (no odd character):
Also viewed with a hex editor and there's nothing there:
I inspected the vcdevcmd.bat file and it's failing at this:
#REM *****************************************************************
#REM This section executes all .bat files found in vsdevcmd\ext.
#REM Any "leaf node" script should be placed in this directory.
#REM A few notes:
#REM * For determinism sake, the scripts are called in alphabetical
#REM order.
#REM * This section does NOT recursively look in sub-directories
#REM under vsdevcmd\ext. Sub-directories may be used for
#REM "implementation detail" scripts called by .bat files in the
#REM vsdevcmd\ext folder.
#REM *****************************************************************
#REM Iterate through ext scripts
if NOT EXIST "%VS150COMNTOOLS%vsdevcmd\ext\" (
#echo [ERROR:%~nx0] Cannot find 'ext' folder "%VS150COMNTOOLS%vsdevcmd\ext\"
set /A __vscmd_vsdevcmd_errcount=__vscmd_vsdevcmd_errcount+1
goto :ext_end
)
for /F %%a in ( 'dir "%VS150COMNTOOLS%vsdevcmd\ext\*.bat" /b /a-d-h /on' ) do (
call :call_script_helper ext\%%a
)
:ext_end
set __vscmd_dir_cmd_opt=
exit /B 0
with the error:
'"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\vsdevcmd\ext\"' is not recognized as an internal or external command,
operable program or batch file.
[ERROR:ext\] init:FAILED code:1
Now I'm not even sure if these 2 errors are related but both appear in the logs. I have attempted complete removed of VS and all of it's products. I've reinstalled with a fresh installer, to no avail.
Thing is, I had this working initially.
Edit 2
Ok, here is the problem with being unable to load VC++ tools (from vcvars.bat):
:export_env_vctoolsinstalldir
if exist "%VCINSTALLDIR%Tools\MSVC\%__VCVARS_TOOLS_VERSION%\" (
set "VCToolsInstallDir=%VCINSTALLDIR%Tools\MSVC\%__VCVARS_TOOLS_VERSION%\"
set "VCToolsVersion=%__VCVARS_TOOLS_VERSION%"
) else (
set VCToolsInstallDir=
if "%VSCMD_DEBUG%" GEQ "2" #echo [DEBUG:%~nx0] Could not find VC++ tools version "%__VCVARS_TOOLS_VERSION%" under "%VCINSTALLDIR%Tools\MSVC\".
goto :end
)
I can't find any env. variables set for __VCVARS_TOOLS_VERSION or VCVARS_TOOLS_VERSION. If I could set that, maybe I can get it to work.
Found this at the head of the same file:
if "%__VCVARS_VERSION%" NEQ "" (
set __VCVARS_TOOLS_VERSION=%__VCVARS_VERSION%
goto :export_env_vctoolsinstalldir
)
I attempted to set that variable and rerun vcdevcmd but it still failed:
set __VCVARS_VERSION=14.16.27023
Also tried:
vsdevcmd -arch=amd64 -host_arch=amd64 -vcvars_ver=14.16.27023
That produces the error:
[DEBUG:vcvars.bat] Checking architecture { host , tgt } : { x86 , x86 }
[DEBUG:vcvars.bat] Could not add directory to PATH: "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCPackages"
[DEBUG:vcvars.bat] Could not find VC++ tools version "14.16.27023" under "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\".
[DEBUG:ext\vcvars.bat] init:COMPLETE
After building, FlashDevelop will run this in Project > Properties > Build > Post-Build Command Line:
"$(ProjectDir)\debug-android.bat"
The bat file will install my game on my phone. It's supposed to run only on Android target. But it also runs on Flash target. So how to disable it on Flash target?
You could pass the TargetBuild variable to your .bat file:
$(ProjectDir)\debug-android.bat $(TargetBuild)
Then simply exit early if the argument value is not android:
if not %1 == android goto :eof
echo Running on android
Check Project -> Properties -> Build -> Builder... for all available variables and their current value.
Is there anyway I can test pre-built event command line, from visual studio command prompt or from any other tool?
I have this event
REM C:\Program Files\TortoiseSVN\bin\SubWCRev.exe $(SolutionDir). $(SolutionDir)\mynamespace\Release.tmpl $(SolutionDir)\mynamespace\Release.txt
But it does not seems to work (Nothing happens). I also tried to execute this command from simple comand prompt, still without success. any help would be great.
However, if I remove the REM from the front, I get the following error message (as mentioned by #Giorgi):
The command "C:\Program Files\TortoiseSVN\bin\SubWCRev.exe
"C:\Projects\GUI\RTS\Development."
"C:\Projects\GUI\RTS\Development\mynamespace\Release.tmpl"
"C:\Projects\GUI\RTS\Development\mynamespace\Release.txt""
exited with code 9009.
You have REM there.
It means that the line is a comment.
Try deleting REM.
Change
REM C:\Program Files\TortoiseSVN\bin\SubWCRev.exe $(SolutionDir). $(SolutionDir)\mynamespace\Release.tmpl $(SolutionDir)\mynamespace\Release.txt
to
C:\Program Files\TortoiseSVN\bin\SubWCRev.exe $(SolutionDir). $(SolutionDir)\mynamespace\Release.tmpl $(SolutionDir)\mynamespace\Release.txt
I have a teamcity build running grunt as a command line task.
When I execute grunt default the output (in the Teamcity logs) does not contain the relevant error output from grunt. It do however return the appropriate non-zero exit code, which cause the teamcity build to fail correctly. I do not get the grunt error log though.
This page: https://www.npmjs.org/package/grunt-teamcity describes the following workaround for the issue that I'm facing:
Teamcity on windows does not flush the stdout stream before exiting
the grunt node process. There has been some work around this in both
nodejs and grunt, but it is by no means resolved. If you see missing
output in your Teamcity build log then try running the grunt task
using the TC command line runner by redirecting output to a file, e.g:
grunt default --no-color > grunt.tmp & type grunt.tmp & del grunt.tmp
Seems that by redirecting to a file the output is synchronous, whereas
with pipe (or TC plugin execute method) the output is async and not
captured before the node process exits.
So it basically suggest that you run grunt like this: grunt default --no-color > grunt.tmp & type grunt.tmp & del grunt.tmp. The problem with this approach however is that is always return 0 (zero) as the exit code, which mean that my Teamcity build does not properly fail.
I imagine this can be fixed with some creative batch scripting, but I'm not sure how to approach this.
#echo off
:: prepare environment
setlocal enableextensions
set "tempFile=%temp%\%~nx0.%random%.grunt.tmp"
:: run grunt
call grunt default --no-color > "%tempFile%"
:: Keep the grunt exit code
set "exitCode=%ERRORLEVEL%"
:: Print the grunt output
type "%tempFile%"
:: cleanup and exit with adecuated value
del /q "%tempFile%" >nul 2>nul
endlocal & exit /b %exitCode%
call grunt default --no-color > temp.txt
type temp.txt
I'm setting up a build server for a Visual Studio 2012 project and I'm trying to add detection for failed builds so the server can properly recover after a build failure and notify users of the failure and the error message.
I'm using devenv.exe with the "/Build" and "/Out" switches, however for building, the "/Out" switch captures all build output and stores in the specified file, and I only want it to capture build errors.
Does anyone have any suggestions on how I can only have build errors written to the file, or better ways of detecting a build failure?
Thank you in advance!
If you just need a pass/fail, you could use ERRORLEVEL in a batch/cmd script. It's primitive, but would probably work for most cases. Something like this:
#devenv Solution.sln /Build
#if ERRORLEVEL 1 echo Build Failed
You could also use MSBuild, which has options for console output (i.e. /clp:ErrorsOnly) as well as file output. Something like this:
msbuild /p:Configuration=Debug /t:Rebuild /clp:ErrorsOnly Solution.sln