Hack 78. Launch Visual Studio from the Command Prompt

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.
|
10.3.1. 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 14This 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
Windows option from the Show Settings drop-down.
10.3.2. 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 commandI almost always open
Visual Studio with the intent of opening a solution, so this saves a
couple of mouse clicks:
C:\> devenv /command File.OpenSolutionWhen 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.
10.3.3. 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.slnWhen 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.
10.3.4. 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 releaseAfter the /build
switch, you specify the solution configuration that you want to use
when building this solutionin 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 Table 10-1.
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 |
10.3.5. 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 Table 10-2.
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. |