3.3. Other Options

Many options that we haven't yet touched on can be used to tweak the way Visual Studio operates. Through the remainder of this chapter you will see some of the more useful options that can help you be more productive.

3.3.1. Keyboard Shortcuts

Visual Studio 2008 ships with many ways to perform the same action. Menus, Toolbars, and various tool windows provide direct access to many commands, but despite the huge number available, many more are not accessible through the graphical interface. Instead, these commands are accessed (along with most of those in the menus and Toolbars) via keyboard shortcuts.

These shortcuts range from the familiar Ctrl+Shift+S to save all changes, to the obscure Ctrl+Alt+E to display the Exceptions dialog window. As you might have guessed, you can set your own keyboard shortcuts and even change the existing ones. Even better, you can filter the shortcuts to operate only in certain contexts, meaning you can use the same shortcut differently depending on what you're doing.

Figure 3-14 shows the Keyboard node in the Environment section of the Options dialog with the default keyboard mapping scheme selected. If you want to change to use a different keyboard mapping scheme, simply select it from the drop-down and hit the Reset button.

The keyboard mapping schemes are stored as .VSK files at C:Program FilesMicrosoft Visual Studio 9.0Common7IDE. This is the keyboard mapping file format used in versions of Visual Studio prior to Visual Studio 2005. To import keyboard mappings from Visual Studio 2005, use the import settings feature (see the Importing and Exporting Settings); for earlier versions copy the appropriate .VSK file into the aforementioned folder, and you will be able to select it from the mapping scheme drop-down the next time you open the Options dialog.

The listbox in the middle of Figure 3-14 lists every command that is available in Visual Studio 2008. Unfortunately, this list is quite extensive and the Options dialog is not resizable, which makes navigating this list difficult. To make it easier to search for commands, you can filter the command list using the "Show commands containing" textbox. In Figure 3-14 the word build has been used to filter the list down to all the commands starting with or containing that word. From this list the Build.BuildSolution command has been selected. As there is already a keyboard shortcut assigned to this command, the "Shortcuts for selected command" drop-down and "Remove" button have been enabled. It is possible to have multiple shortcuts for the same command, so the drop-down enables you to remove individual assigned shortcuts.

Having multiple shortcuts is useful if you want to keep a default shortcut — so that other developers feel at home using your setup — but also add your own personal one.

Figure 3.14. Figure 3-14

The remainder of this dialog enables you to assign a new shortcut to the command you have selected. Simply move to the "Press shortcut keys" textbox and, as the label suggests, press the appropriate keys. In Figure 3-14 the keyboard chord Ctrl+Alt+B has been entered, but this shortcut is already being used by another command, as shown at the bottom of the dialog window. If you click the "Assign" button, this keyboard shortcut will be remapped to the Build.BuildSolution command.

To restrict a shortcut's use to only one contextual area of Visual Studio 2008, select the context from the "Use new shortcut in" drop-down list. The Global option indicates that the shortcut should be applied across the entire environment, but we want this new shortcut to work only in the editor window, so the Text Editor item has been selected in Figure 3-14.

Chapter 53 deals with macros that you can create and maintain to make your coding experience easier. These macros can also be assigned to keyboard shortcuts.

3.3.2. Projects and Solutions

Several options relate to projects and solutions. The first of these is perhaps the most helpful — the default locations of your projects. By default, Visual Studio 2008 uses the standard Documents and Settings path common to many applications (see Figure 3-15), but this might not be where you'll want to keep your development work.

Figure 3.15. Figure 3-15

You can also change the location of template files at this point. If your organization uses a common network location for corporate project templates, you can change the default location in Visual Studio 2008 to point to this remote address rather than map the network drive.

There are a number of other options that you can adjust to change how projects and solutions are managed in Visual Studio 2008. One of particular interest is Track Active Item in Solution Explorer. With this option enabled, the layout of the Solution Explorer changes as you switch among items to ensure the current item is in focus. This includes expanding (but not collapsing again) projects and folders, which can be frustrating on a large solution as you are continually having to collapse projects so that you can navigate.

Another option that relates to solutions, but doesn't appear in Figure 3-15, is to list miscellaneous files in the Solution Explorer. Say you are working on a solution and you have to inspect an XML document that isn't contained in the solution. Visual Studio 2008 will happily open the file, but you will have to reopen it every time you open the solution. Alternatively, if you enable Environment Documents Show Miscellaneous Files in Solution Explorer via the Options dialog, the file will be temporarily added to the solution. The miscellaneous files folder to which this file is added is shown in Figure 3-16.

Figure 3.16. Figure 3-16

Visual Studio 2008 will automatically manage the list of miscellaneous files, keeping only the most recent ones, based on the number of files defined in the Options dialog. You can get Visual Studio to track up to 256 files in this list, and files will be evicted based on when they were last accessed.

3.3.3. Build and Run

The Projects and Solutions Build and Run node, shown in Figure 3-17, can be used to tailor the build behavior of Visual Studio 2008. The first option to notice is "Before building." With the default option of "Save all changes," Visual Studio will apply any changes made to the solution prior to compilation. In the event of a crash during the build process or while you're debugging the compiled code, you can be assured that your code is safe. You may want to change this option to "Prompt to save all changes" if you don't want changes to be saved prematurely, though this is not recommended. This setting will inform you of unsaved modifications made in your solution, enabling you to double-check those changes prior to compilation.

Figure 3.17. Figure 3-17

In order to reduce the amount of time it takes to build your solution, you may want to increase the maximum number of parallel builds that are performed. Visual Studio 2008 can build in parallel only those projects that are not dependent, but if you have a large number of independent projects this might yield a noticeable benefit. Be aware that on a single-core or single-processor machine this may actually increase the time taken to build your solution.

Figure 3-17 shows that projects will "Always build" when they are out of date, and that if there are build errors the solution will not launch. Both these options can increase your productivity, but be warned that they eliminate dialogs letting you know what's going on.

The last option worth noting in Figure 3-17 is "MSBuild project build output verbosity." In most cases the Visual Studio 2008 build output is sufficient for debugging build errors. However, in some cases, particularly when building ASP.NET projects, you will need to increase verbosity in order to diagnose the build error.

3.3.4. VB.NET Options

VB.NET programmers have four compiler options that can be configured at a project or a file level. You can also set the defaults on the Projects and Solutions VB Defaults node of the Options dialog. Previous versions of Visual Basic had an Option Explicit, which forced variables to be defined prior to their use in code. When it was introduced, many experts recommended that it be turned on permanently because it did away with many runtime problems in Visual Basic applications that were caused by improper use of variables.

Option Strict takes enforcing good programming practices one step further by forcing developers to explicitly convert variables to their correct types, rather than let the compiler try to guess the proper conversion method. Again, this results in fewer runtime issues and better performance.

We advise strongly that you use Option Strict to ensure that your code is not implicitly converting variables inadvertently. If you are not using Option Strict, with all the new language features, you may not be making the most effective use of the language.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.136.226