Thursday, December 02, 2010

Build Visual Studio solution from command line or batch file

Following simple batch file can be used to build a solution in Visual Studio 2010. Here I use devenv.exe to build the solution from command line so that we get the same behavior as if building from IDE. Save below given batch script into a .bat file, update the solution file path and you are all set to build.

echo off

call "C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"
devenv "C:\SampleWinApplication\SampleWinApplication.sln" /build


vcvars32.bat sets up environment for Visual Studio Tools. Note that this same batch file is called when you invoke Visual Studio command prompt (Start->Programs->Microsoft Visual Studio 2010->Visual Studio Tools—>Visual Studio Command Prompt (2010). This is important to correctly invoke devenv from command line.


Sanjay Singh said...

There are several other switches supported by devenv. For example you can /rebuild, /clean etc. For all the supported switches see help (devenv /?)

Iftekhar Alam said...

It helps to solve my problem. Thank You

Nitesh said...

Hi how to write the same in to file

Vips said...

Can I build selective project from my solution ?