Launch Visual Studio from the Command Prompt





Launch Visual Studio from the Command Prompt

If you want to exercise obsessive control about how Visual Studio is launched, you'll be pleased to know that you can do it all from your friendly neighborhood command prompt.

The Visual Studio IDE executable is called devenv.exe and includes a number of command-line switches that can be very useful. Elsewhere in this book, we have looked at a couple of these switches, but in this hack, you will learn about all the switches and how they can be used.

Typing command-line switches every time you launch an application is time consuming and just plain inefficient. Remember that you can create shortcuts that call an executable using command-line switches; you could have a number of different shortcuts for Visual Studio with different command-line switches.


Setting Fonts

One of the simplest, but very useful, things you can accomplish using command-line switches is setting the font and font size for the IDE. To specify the font, you can use the /fn switch, and to specify the size, you use /fs. It is important to note that this is not the font size of the text or contents of your files, but rather the text size of the IDE. You won't see it affect the normal menus, but the font and size of the document tabs, options dialog, and so forth will all be in the specified font type and size.

The following command line could be used to set the Visual Studio IDE font to Verdana and the size to 14:

C:\> devenv /fn Verdana /fs 14

This does not need to be set each and every time you run the IDE; these settings will be saved and used from here on out. This is the same setting you can configure under Tools Options Fonts and Colors, then selecting the Dialogs and Tool Windows option from the Show Settings drop-down.

Execute a Command

Using the command switch, you can launch Visual Studio and automatically call a Visual Studio command. All you need to do is specify the switch /command and then follow it with the name of the command that you want to execute. These are the same commands covered in [Hack #46]. In this example, I will call the File.OpenSolution command—I almost always open Visual Studio with the intent of opening a solution, so this saves a couple of mouse clicks:

C:\> devenv /command File.OpenSolution

When you run this command, Visual Studio will open, and the New Solution dialog will open. You could also use /command to execute a macro you have written to perform more complex actions.

Run a Solution

You can automatically run a solution from the command line using the /run switch. The following is an example of running a solution from the command line:

C:\> devenv /run HacksWinSample.sln

When this command is run, the IDE will open and automatically jump into debug mode loading your application. You can also use the /runexit switch, which will launch your applications and minimize the IDE. When you close your application, the IDE will be closed as well.

Building Projects and Solutions

You can build your projects or solutions using command-line switches. This can be a great alternative if you don't have time to configure a build tool like NAnt, but want to create a build process using a batch file. To build a solution, you use the /build switch as well as the /project or /solution switch. Here is an example of building a solution from the command line:

C:\> devenv HacksWinSample.sln /build release

After the /build switch, you specify the solution configuration that you want to use when building this solution—in this example, I have used the release configuration. Running this will build the solution without opening the IDE, and the build results will be returned to the command prompt window. A number of other build switches are detailed in Figure.

Build switches

Switch

Description

/clean

Cleans the project or solution according to the configuration of that project or solution

/rebuild

Cleans and builds the project or solution

/project

Specifies the project to build

/projectconfig

Specifies the configuration to use when building the project

/deploy

Tells Visual Studio to deploy the solution after it has been built

/out

Specifies the name of a file to send any build errors to


Other Switches

A number of other command-line switches can be used to do various things with Visual Studio. These command-line switches are shown in Figure.

Command-line switches

Switch

Description

/lcid

Specifies the default language to use for the IDE. Example: devenv /lcid 1033

/mdi

Specifies that Visual Studio should be run in MDI mode.

/mditabs

Specifies that Visual Studio should be run in MDI mode with tabs on documents enabled.

/migratesettings

Tells Visual Studio to trigger the settings migration process, which can be used to move settings from one version of Visual Studio to another. (You usually see this screen the first time you run a new installation of Visual Studio.)

/nologo

Launches Visual Studio without the splash screen.

/noVSIP

Disables a developer's VSIP license on this workstation.

/safemode

Specifies that Visual Studio should open without loading any VSIP packages.

/setup

Resets certain parts of Visual Studio ([Hack #92]).

/resetskippkgs

Enables VSIP packages by clearing any SkipLoading tags. After running safe mode, this will need to be run to reenable any packages you still want to run.

/rootsuffix

Can be used to specify a registry suffix [Hack #30] .

/?

You can always use this switch to view the help for devenv.exe.



     Python   SQL   Java   php   Perl 
     game development   web development   internet   *nix   graphics   hardware 
     telecommunications   C++ 
     Flash   Active Directory   Windows