Did you know… How to build a solution from the command lineI


I’d recommend using the Visual Studio 2005 Command Prompt from All Programs – Microsoft Visual Studio 2005 – Visual Studio Tools, so you don’t have to worry about setting your PATH properly.

If you do a
Devenv /?
From the command prompt, you’ll get a long usage statement.  Here’s what you need to know in order to build.

In the usage, you’ll see the following example:
devenv solutionfile.sln /build solutionconfig [ /project projectnameorfile [ /projectconfig name ] ]

The minimum you’ll need to build is
devenv <solutionname> /build

You can also specify the solution configuration and the project configuration.  You can use or create new project and solution configurations from within Visual Studio at Build – Configuration Manager.   For example:
devenv <solutionname> /build "Debug|Any CPU" /project <projectname> /projectconfig “Debug|Any CPU”

And lastly, you can specify where to write the build log to.
devenv <solutionname> /build "Debug|Any CPU" /project <projectname> /projectconfig “Debug:Any CPU” /out <filename>

Happy Visual Studio’ing!

Comments (7)

  1. Bao says:

    Forgive me if I’m not understanding things, but is there a reason why solutions in 2005 weren’t converted to the MSBuild format?

  2. saraford says:

    Basically, we didn’t have time in the Whidbey product cycle to finish the work.

    Thanks,

    -sara

  3. MarcT says:

    How does one build an asp.net 2.0 project?  SInce there isn’t a csproj file anymore, how do you reference it to make it build with a particular configuration (like Release) when it’s default to "Debug"?

  4. Marc says:

    devenv doesn’t seem to recognize sln’s that are in a different location than the current working directory.  Trying do to devenv ..mysol.sln /build "Release" /project myproj.csproj /projectconfig Release

    fails.  However, cd’ing .. and running

    devenv mysol.sln /build "Release" /project myprojmyproj.csproj /projectconfig Release works.  

    I too have the same question about asp.net 2.0 apps.  Plus, clean doesn’t seem to clean out the bin directory, so if a reference changes, it doesn’t seem to pick it up based on date/time stamp.  

    Plus, how can you precompile stuff?  I don’t see a "Publish" parameter, let alone publishing a release configuration without having to checkout web.config to change debug to false.

    Plus, I hate that you can’t tell which path the references are using since there’s no proj file to look at for hintpaths.

    It makes it very very difficult to build purely from the command line.  They should make every effort to make commandline builds do the same thing as gui builds, especially if you are a release engineer needing to build multiple projects scattered throughout different source control repositories.  

  5. Marc says:

    I think I found my answers to some of my questions, at least with respect to publishing and cleaning.

    For asp.net 2 projects, since there’s no proj file, if a developer adds a new reference that works for them, when I build, I will obviously break because, even if I update, I won’t be able to load the new reference since there’s no way for the reference to be identified ahead of time (which is bad design) if the reference isn’t in the web.config.  But once I identify the missing reference, I can copy the dll into the bin directory.  

    Basically, I delete the contents of the bin directory, copy the newly built reference dlls into it, then build.  It’s stupid that i have to do this, but it works.  I wish Microsoft had gone the classpath way of Java, which is much easier than compile/break/add missing reference/compile/break in new spot/add missing reference/loop some more.

    To publish, I has to go to aspnet_compiler.asp which is found in %windir%Microsoft.netFramework2*.  I am still experimenting with that line.

  6. Marc says:

    whoops! I meant aspnet_compiler.exe!

    One other thing is if there’s a sln with several projects, one of which is an asp.net app, and that asp.net 2 app has dependencies on one or more of the other projects within the sln.  If you delete the contents of the asp.net project’s bin directory, the asp.net project will fail because it’s not smart enough to copy the reference dependency(s) in the bin directory in a commandline build.

    For example, in a two project solution, mydll and my_aspnet, and my_aspnet depends on mydll.  You delete the contents of my_aspnetbin, then do a devenv on the solution, mydll builds successfully, and my_aspnet will fail over not finding mydll.dll (when building from commandline).  

    You have to build mydll separately, then copy mydll.dll into my_aspnetbin, then my_aspnet will build successfully (after rebuilding mydll because you have to build the entire solution all over because there’s no csproj file to use if you need to "build" only my_aspnet).