A recent issue with my Visual Studio 2010 installation introduced me to the command line options for running the IDE. While I was aware of the command line options, I did not realize there was such an abundance of them. In order to help you take full advantage of the Visual Studio 2010 environment, I recount what happened with my installation and cover the other command line switches available.
Working with the command line
Any version of Visual Studio may be launched from a command line by typing devenv.exe. You may use the Visual Studio Command Prompt (which is available in the Visual Studio Tools area of an installation), or you can use the usual Run command prompt. This does require the path to devenv.exe be in the path on your computer (the path for default Visual Studio 2010 installation on Windows XP is C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE). One space should separate the devenv command and any switches or options. The command line switches are not case-sensitive.
Problems launching the Visual Studio IDE
I encountered error messages referring to problems connecting to a database when launching my instance of the Visual Studio 2010 IDE. After digging around the Web (thank you, Google), I used command line switches to reset my Visual Studio instance. The following switches are available to work with a problematic installation:
- Command/CommandLine: Executes a specified command after Visual Studio is launched. One example is launching the open project option (devenv /Command File.OpenProject). There is a complete list of Visual Studio 2010 commands online.
- InstallVSTemplates: Registers project/item templates located in the ProjectTemplates and ItemTemplates subdirectory of the Visual Studio installation path.
- Log <log file>: Launches the IDE and logs all activity related to the IDE to the specified log file. This option is useful when debugging startup problems and may point you to other available command line switches like removing a problematic add-in.
- ResetAddin <Namespace.class>: Removes commands and associated buttons for the specified main class of the Visual Studio add-in. You can use the asterisk (ResetAddin *) to reset all add-ins.
- ResetSettings: Restores Visual Studio to its default settings. You may include an optional settings file parameter to specify the settings to apply to the IDE.
- ResetSkipPkgs: Clears all skip loading options added by a user, thus re-enabling the loading of the VSPackage.
- SafeMode: This option is analogous to launching Windows into safe mode to investigate problems. It launches the IDE into safe mode, which means it loads only the default environment and services and any shipped versions of third-party packages. This can be used to identify any problem with third-party add-ins or packages.
- Setup: Forces Visual Studio to merge resource metadata that describes menus, toolbars, and command groups from all VSPackages available. It takes no arguments and does not load the IDE — it performs the final step of the setup process. This command must be run under Administrator level permissions.
For my problem, I ended up using the log option, which led to totally resetting my environment via the ResetSettings switch. It was a drastic measure, but it didn't cause me as many problems as it may other developers who have various add-ins installed. The log option generates an XML-based log file with information on your Visual Studio installation including the environment and add-ins. The following snippet shows the beginning of a log file for my current installation that launches with no issues. The root activity node contains entry nodes with information; the three entries in this example display the Visual Studio version, security level, and current disk space.
<?xml-stylesheet type="text/xsl" href="ActivityLog.xsl"?>
<description>Microsoft Visual Studio 2010 version: 10.0.30319.1</description>
<description>Running in User Groups: Administrators Users</description>
<description>Available Drive Space: C:\ drive has 98688417792 bytes</description></entry>
Working with code
In addition to the switches available to address IDE issues, there are options for building, debugging, and executing code from the command-line; this allows you to automate or streamline some common actions. This list is a subset of these options:
- Clean: Cleans up the environment by deleting build output files.
- Build: Builds a solution/project with a specified configuration.
- Rebuild: The environment is cleaned, and then the specified solution/project is built.
- Deploy: The specified build configuration is built and deployed.
- Run: The IDE is opened, and the specified solution is compiled and executed.
- RunExit: This is the same as the Run command, except the IDE is closed after execution.
The following command line option allows you to get a full list of the available switches:
Control at your fingertips
The Visual Studio command line options give you a way to address installation issues, as well as issue commands and work with source code using the many IDE features. These switches were instrumental in getting my environment up and running without performing a dreaded reinstall.
Tony Patton has worn many hats over his 15+ years in the IT industry while witnessing many technologies come and go. He currently focuses on .NET and Web Development while trying to grasp the many facets of supporting such technologies in a production environment on a daily basis.