views:

3179

answers:

8

How do you turn a Visual Studio build that you'd perform in the IDE into a script that you can run from the command line?

Update: To those also looking for the answer to this question, please check the Related box to the right as several similar questions have been asked.

+2  A: 

Look into build tool NAnt (http://nant.sourceforge.net/) or MSBuild (http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx). I believe MSBuild is the build tool for VS2005+, I am however a fan of NAnt...

mmattax
+1  A: 

Simplest way: navigate to the directory containing the solution or project file, and run msbuild (assuming you have Visual Studio 2005 or newer).

More flexible ways:

  • read up on the MSBuild reference. There's tons of customization, especially once you've installed the community tasks.
  • use NAnt. It has existed for longer than MSBuild and has more community support, but requires you to start a project file from scratch, rather than extending the existing, VS-created one.
Sören Kuklau
+13  A: 
\Windows\Microsoft.NET\Framework\[YOUR .NET VERSION]\msbuild.exe

Lots of command line parameters, but the simplest is just:

msbuild.exe yoursln.sln
FlySwat
+2  A: 

nant and msbuild are the most popular tools to automate your build in .net, and you can can find a discussion on there the pros/cons of each in this question "best .net build tool"

alanl
+1  A: 

I had to do this for a C++ project in Visual Studio 2003 so I don't know how relevant this is to later version of visual studio:

In the directory where your executable is created there will be a BuildLog.htm file. Open that file in your browser and then for each section such as:

Creating temporary file "c:\some\path\RSP00003C.rsp" with contents
[
/D "WIN32" /D "_WINDOWS" /D "STRICT" /D "NDEBUG" ..... (lots of other switches)
.\Project.cpp
.\Another.cpp
.\AndAnother.cpp
".\And Yet Another.cpp"
]
Creating command line "cl.exe @c:\some\path\RSP00003C.rsp /nologo"

create a .rsp file with the content between the square brackets (but not including the square brackets) and call it whatever you like. I seem to remember having problems with absolute paths so you may have to make sure all the paths are relative.

Then in your build script add the command line from the BuildLog.htm file but with your .rsp filename:

cl.exe @autobuild01.rsp /nologo

(note there will also be a link.exe section as well as cl.exe)

Sam Hasler
+1  A: 

As of VS2005, all of the project files (at least for .NET based projects) are actual MSBuild files, so you can call MSBuild on the command line and pass it the project file.

Bottom line is that you need to use a "build scripting language" like NAnt or MSBuild (there are others, but these are the mainstream ones right now) if you want to have any real control over your build process.

Scott Dorman
+9  A: 

With VS2008 you can do this:

devenv solution.sln /build configuration
Vulcan Eager
This way always seems the easiest.
Aardvark
+1  A: 

Take a look at UppercuT. It has a lot of bang for your buck and it does what you are looking for and much more.

UppercuT uses NAnt to build and it is the insanely easy to use Build Framework.

Automated Builds as easy as (1) solution name, (2) source control path, (3) company name for most projects!

http://projectuppercut.org/

Some good explanations here: UppercuT

ferventcoder