CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Raymond Lewallen

Framework Design, Agile Coach, President Oklahoma City Developers Group, Microsoft MVP C#, TDD, Continuous Integration, Patterns and Practices, Domain Driven Design, Speaker, VB.Net, C# and Sql Server

Using Devenv at the command prompt to build projects

We all know about NAnt, MsBuild and some other build tools.  People are very aware of these, but seem to be unaware that you can create your own build batch file just by using visual studio and the command prompt.

Let’s say you have 2 solutions, a solution with business objects and business rules assemblies, and another solution just for an Asp.Net GUI project.  We can easily build a batch file to compile these three projects:

Batch file build

REM Builds projects in debug mode

REM Build data project

Devenv /build debug /project DataAccess "C:\Projects\WebApplication\BusinessProjects.sln"

REM Build business rules project

Devenv /build debug /project BusinessRules "C:\Projects\WebApplication\BusinessProjects.sln"

REM Build web application

Devenv /build debug /project WebApplication "C:\Inetpub\wwwroot\WebApplication\AspWebApplication.sln"

Voila!  Run the batch file to build everything in debug build.

  • “Devenv” is the IDE executable.
  • /build is the switch to build the project.  It takes either “debug” or “release” as arguments.  Change “debug” to “release” to build everything in release mode.
  • /project and its argument specifiy the name of the project to build within a solution.
  • The final argument for “devenv” is the location of the solution file that contains the project you want to build.

Note:  This works for .Net IDE 2002 and 2003.  I have not tried this with 2005 yet.  If anyone has, let me know of the changes in the comments below.

You can do “devenv /?” at the command prompt to list all available switches for Devenv, with descriptions of their uses.

From MSDN Documentation:

 The following syntax rules apply to all switches and arguments:

  • The command line syntax must start with devenv. For example, to use the /fn switch you would type the following:
    devenv /fn arial
  • Switches are not case sensitive.
  • The first argument is typically a solution file name.
  • When you supply a project file name instead of a solution file name, Devenv does the following:
    • Searches the parent directory of the project file for a solution file of the same name. For example, if you specify myproject1.vbproj, Devenv looks for myproject1.sln.
    • Searches for a single solution file with a reference to the project file in the parent directory of the project file. If more than one solution references the project file or no solutions reference the project file, a temporary solution with the same name as the project file is created.
  • File paths and file names that include spaces must be enclosed in double quotation mark ("").
  • Include the drive letter when specifying file paths.
  • Separate multiple switches and arguments with one white space character.
  • Devenv does not accept wildcards or other pattern matching syntax.

Use the following command line switches to display the integrated development environment and perform the described task.

Command line switch Description
/lcid or /l Sets the default language for the IDE.
/fn Changes the system font for the IDE.
/fs Changes the system font size for the IDE.
/run or /r Compiles and runs the specified solution.
/runexit Compiles and runs the specified solution, minimizing the IDE when the solution is run, and closing the IDE after the solution has completed running.
/mdi Opens the IDE in multiple-document interface (MDI) mode. In addition, the MDI environment option in the Options dialog box is selected. For more information, see General, Environment, Options Dialog Box.
/mditabs Opens the IDE in MDI mode with the tabs on documents enabled.
/command Starts the IDE and executes the specified command.
/migratesettings Opens the IDE and copies certain Options dialog box settings from a pervious version to the more recent version.
/debugexe Loads a Visual C++ executable under the control of the debugger. This switch is not available for Visual Basic or Visual C# executables. For more information, see Launching the Debugger Automatically.
/useenv Causes the integrated development environment (IDE) to use PATH, INCLUDE, and LIB environment variables for Visual C++ compilation rather than the settings specified in the VC++ Directories section of Projects options in the Options dialog box. For more information, see Setting the Path and Environment Variables for Command-Line Builds

Use the following command line switches to perform the described task. These command line switches do not display the integrated development environment.

Command line switch Description
/build Builds the specified solution or project according to the specified solution configuration.
/rebuild Cleans and then builds the specified solution or project according to the specified solution configuration.
/project The project to build, clean, or deploy. You can use this switch only if you have supplied the /build, /rebuild, /clean, or /deploy switch.
/projectconfig Specifies the project configuration to build or deploy. You can use this switch only if you have supplied the /project switch.
/clean Cleans the specified solution or project according to the specified solution configuration.
/deploy Causes deployment after a build (or a rebuild) according to the specified solution configuration.
/out Allows you to specify a file to receive errors when you build.
/nologo Prevents copyright information from displaying.
/? Displays help inside the Command Prompt window for Devenv switches.

The following switches are available only to those companies who participate in the Visual Studio .NET Integration Program (VSIP).

Command line switch Description
/noVSIP Disables the VSIP developer's license key on a developer workstation.
/safemode Launches Visual Studio in safe mode, loading only the default environment and services.
/resetskippkgs Clears all SkipLoading tags added to VSPackages by users wishing to avoid loading problem VSPackages.


Comments

Jeremy D. Miller said:

You *can* do this, but it executes a lot slower than the NAnt <solution> task. We used to whimp out and use this for CruiseControl builds back when the <solution> task wasn't usable (I tried Slingshot but thought it was way too flaky).
# July 20, 2005 8:49 AM

Raymond Lewallen said:

It does execute slower, no doubt. For something quick and dirty it works well, especially if you have small builds. The imports, references and included source files are already contained in the projects .cproj or .vbproj file.
# July 20, 2005 9:20 AM

Jay said:

I have X.sln which is having X.vcproj & Y.vcproj. Both in ClearCase. I need to build only X.vcproj. This is failing because X.sln is configured to build both the projects
# May 25, 2006 2:34 AM

Raymond Lewallen said:

Jay, you'd have to configure the solution to only build the project you want built.  DevEnv takes information from the solution file and does whatever it says.  If you only want it to build one, you have to set that in  the solution file.
# May 25, 2006 9:42 AM

Cristian said:

OK, so how can you capture all ".sln" solution on CMD? So, here is what I do: CMD:> devenv.exe my.sln /Build /Release after I press ENTER, the above command ends. Looking in my TaskManager, the devenv.exe along with cl.exe/s will work. Why can I just see all build process on my CMD and have my command finish when the build is finished by a successful release or build errors. For those who know the answer, I would be more than happy to see it by mail: cristian.oanceaATyahooDOTcom
# March 14, 2008 4:01 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Raymond Lewallen

Working primarily in the public sector during his career, Raymond has designed and built several high profile enterprise level applications for all levels of the government. Raymond now works as a solutions architect for EMC. Raymond is an agile coach, Microsoft MVP C# and also president of the Oklahoma City Developers Group and Oklahoma Agile Developers Group. Raymond spends a lot of his time learning and teaching such things as Test Driven Development, Domain Driven Design, Design Patterns and Extreme Programming practices and principles, to name a few. Raymond is also an advocate of Alt.Net. Raymond is primarily a framework guy, so don't ask him anything about UI :) Check out Devlicio.us!