How to compile Visual Studio Solution from commandline and check status in DOS BAT file

If you ever tried to automate your build process from commandline then here is easy way to compile your solution

@echo off

SET PROGRAM_32BIT=%ProgramFiles%
if not "%ProgramFiles(x86)%" == "" set PROGRAM_32BIT=%ProgramFiles(x86)%

::TODO: I have this sample for VS2010 but change it according to your VS version
SET DevEnvPath=%PROGRAM_32BIT%\Microsoft Visual Studio 10.0\Common7\IDE
SET BuildLogFile=C:\Setup\BuildErrorLog.txt

DEL /Q "%BuildLogFile%"

"%DevEnvPath%\devenv.exe" /rebuild Release "C:\MyProduct\MyApplication1.sln" /out "%BuildLogFile%"

::=========================
::CHECK FOR ERROR
::=========================

::Find exact string in build log file so we know if it failed?

findstr /M /C:" 0 failed," "%BuildLogFile%" > build_error_found.txt
if %errorlevel%==0 (
echo SUCCESSFULLY Compiled full solution
) else (
echo ERROR occurred during compile. See Build Log for more info
::Terminate Bat File
exit 0
)

::Do more stuff here 
::e.g. obfuscate dlls/exec

::Do more stuff here
::e.g. build setup file

@echo on

 

Binary World is a Software Development company located in Atlanta, USA (since 2007). Binary World specialized in Business Intelligence, mobile, cloud computing and .Net Application Development.

Leave a Reply