Thursday, May 20, 2010

MSBuild: Targeting a Configuration from the Command Line

Update: Read the comments for some good tips from other readers.

Firing up Visual Studio to simply build a solution is nuts. Do it from the Visual Studio Command Prompt instead and save yourself time.

What I always forget, though, is how to specify a release build, ergo I’m writing this blog post so I can quickly find it the next time I need it.

From the command line, use the “/p:” switch and pass the value “Configuration=Release” like so:

msbuild CommunityServer.Sync.sln /p:Configuration=Release

I’m also in the habit of first doing a clean build before the release build to ensure I’ve got no leftover cruft:

msbuild CommunityServer.Sync.sln /target:clean

(Actually, I tie all this stuff together with SlickRun shortcuts and batch files, which is even better!)


Sean said...

One thing to keep in mind - when running clean, you'll want to specify "/p:Configuration=Release" otherwise you'll clean the Debug configuration.

Paul said...

Jim, if you go with something like:
msbuild CommunityServer.Sync.sln /p:Configuration=Release /t:Clean;Build

This will run a clean and then a full build of the solution due to the specified targets switch. If you just go with Clean you won't get build binaries, just removal of the last compilation.

Jim Holmes said...

@Sean & @Paul -- thanks for the clarifications. I was a dork to miss the important issue of specifying WHICH config to clean!

stej said...

I had problems with dependencies when I used just sln file as a source for msbuild.
In this case msbuild wasn't able to figure out what project depends on the other. That's why for each such a sln file I have something like

<Project xmlns="">

<Target Name="CreateProjects" Outputs="@(Projects)">
<Output ItemName="Projects" TaskParameter="Include"/>

<Target Name="Build" DependsOnTargets="CreateProjects">
<Message Text="Projects (pseudo)order: %(Projects.FileName)"></Message>
Targets="Build" StopOnFirstFailure="true">


(copied from psake build. {0} is replaced with actual projects paths)

Leslie Lim said...

This is really an interesting topic. Congratulations to the writer. I'm sure a lot of readers having fun reading your post. Hoping to read more post from you in the future. Thank you and God bless!


Subscribe (RSS)

The Leadership Journey