How do you automate a Visual Studio build?

Viewed 55341

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?

11 Answers

With VS2008 you can do this:

devenv solution.sln /build configuration
\Windows\Microsoft.NET\Framework\[YOUR .NET VERSION]\msbuild.exe

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

msbuild.exe yoursln.sln

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 are tons of customization, especially once you've installed the MSBuild Community Tasks Project.
  • 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, Visual Studio-created one.

NAnt and MSBuild are the most popular tools to automate your build in .NET, and you can find a discussion on there of the pros/cons of each in the Stack Overflow question Best .NET build tool.

Look into build tool NAnt or MSBuild. I believe MSBuild is the build tool for Visual Studio 2005 and later. I am, however, a fan of NAnt...

As of Visual Studio 2005, 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.

The 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.

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

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)

Related