Greetings, dear readers!  Today I want to talk about using devenv.exe to build a solution or project from the command line (as opposed to interactively inside the IDE).  For example, you can say “devenv /build debug myapp.sln” to do a debug build of myapp.sln.  Now, I have to admit that if there was one feature I could deny any association with, it would be this one.  There are many things about this feature that are harder to understand and use than they should be.  (In my defense I can say that this feature took its current form before I took over this area!)  Rest assured, however, that we’re working to make some improvements in this space for Whidbey.


A number of users don’t even know this feature exists.  But it’s very handy.  If you want to build a solution or project from a build script then this lets you do it.  Just type “devenv /?” from the command line to see what you can do.  You can also see the documentation page for a full list of supported switches.  I’m going to focus on the /build switch, but much of what I’m going to say also applies to /clean, /rebuild, and /deploy.  And I’m using VS 2003 but most of these comments should also apply to VS 2002.


A key to understanding this feature is to understand the relationship between solution configurations & project configurations.  See my blog entry from 8/14/03 for more on that.


The most basic operation with devenv /build is to build a whole solution configuration.  This is pretty easy.  If you have a solution called myapp.sln, and it has a configuration called “Debug” (which it normally would by default), then you can build it by typing “devenv /build debug myapp.sln”.  This should give you the same result as if you opened up the IDE, picked that solution configuration, and did Build.Build Solution.  (Note that you can only build one solution, and one solution configuration, at a time.  If you need to build more than one, use a batch file to wrap your calls to devenv.exe.)


Another thing you can do is operate on one project at a time.  If you have myapp.sln that contains proj1.vcproj and proj2.vcproj, you might only want to build one project at a time, without having to define a separate solution configuration.  If you want to do this, understand that you still have to specify a solution configuration to give the build proper context.  This is because some things, like project-to-project references, need a solution configuration context in which to be resolved properly.  Therefore the syntax to build just proj1.vcproj in the solution’s debug configuration would be:


devenv /build debug /project proj1 myapp.sln


This basically says: “Build the debug configuration of myapp.sln, and only include the project proj1 in the build.”


When using the /project switch to specify a specific project to build, you can only specify one project at a time.  If you pass the /project switch multiple times, the last one wins & the prior /project switches are ignored.  If you want to build a certain set of more than one project, you should define a separate solution configuration.


Another thing you can do when building just one project is specify a particular project configuration to be built.  Let’s say I wanted to build just proj1.vcproj again, but this time with the release configuration – and just for fun, using the debug configuration of the solution!  I can do it like this:


            devenv /build debug /project proj1 /projectconfig “release|.net” myapp.sln


The switch we’ve added is /projectconfig, followed by the value of “release|.net”.   Why the funny syntax with “|” instead of just “release”?  The trick here is that the configuration of a project includes not only things like debug/release, but also the platform you’re targeting.  Ordinarily, VB & C# project target the platform “.NET” and VC++ targets the platform “Win32” (even for managed C++, which is confusing).  But if you buy, say, a version of VC++ that targets Win64, that’s another platform choice.  So, just remember than when using the /projectconfig switch you need to add “|” followed by the platform the project targets (which you can see in the Configuration Manager dialog under Build.Configuration Manager).


We hope to make many aspects of “devenv /build” a little easier to use in the next major release, but hopefully this information will make this feature less mystifying for the next time you want to use it.


That’s all for now! -Chris