In continuing to explore all the tools provided by the IDE, this chapter focuses on dialog boxes and smaller, miscellaneous tools in Microsoft Visual Studio. For example, you can have a lot of fun using the Find combo box to run Visual Studio commands, open files, and much more. There are all sorts of tips and tricks here that, even if you don’t use them in your daily coding activities, you can definitely use to impress your coworkers with your mad IDE skills.
Unlike tool windows, which are available at any time, dialog boxes are used when a tool needs to perform some sort of action that can’t or shouldn’t be interrupted. For example, resetting your development settings requires a series of actions that should be done at one time, such as choosing which settings you want to reset to and deciding whether you want to save your current settings. These actions are best handled through a dialog box that walks you through each step instead of a tool window, where you may come back and say, "Hmm, what was I doing again?"
Conversely, having to open a dialog box every time you want to drag and drop a control onto a WinForm designer would get very old very quickly. Because the Toolbox is a tool window and not a dialog box, it can live alongside your WinForm designer for easy access.
The Import And Export Settings feature was the first feature I ever tested from start to finish, from watching the specification get written to shipping the feature in the beta release of Visual Studio 2005. The Import And Export Settings dialog box will always be near and dear to my heart.
The code name for the feature was Profiles. Some of the earliest check-ins even referred to the feature as such in the UI. Something definitely got hard-wired in my head, because I always slip and call the feature Profiles whenever I talk about it. My efforts to deprogram myself have not been successful.
Maybe you don’t remember what you picked during your first launch of Visual Studio or what you last reset to.
Under the HKEY_CURRENT_USERSoftwareMicrosoftVisualStudio9.0Profile key, you’ll see the LastResetSettingsFile value. As previously mentioned, the code name for this feature was Profiles, hence the word Profile is used as the key.
In the following example, you’ll notice how I’m using the General Development Settings.
If you haven’t reset any settings since launching Visual Studio, this value tells you this is what you picked at first launch.
The most popular question I see about Visual Studio IDE is how to reset the environment settings. Starting in Visual Studio 2005, the IDE prompts you on first launch to pick your development settings. If you need to reset back to what you picked or want to pick previously saved settings or predefined settings, go to Tools–Import And Export Settings to launch the wizard, and choose Reset All Settings.
On the next page you decide whether you want to save your current settings. If this is your first time using this dialog box or you want to experiment with this feature, or both, definitely choose to save your settings. The default is to save your settings, so go with the default if you are unsure.
The following page is much more interesting. You may notice this list looks familiar. It should, because this is the same list from that first launch dialog box that prompts you to pick your preferred environment settings. These files contain default settings for features such as keyboard shortcut bindings, tool window layouts, project template layouts, and many, many more.
Choose your IDE settings by clicking Finish. Visual Studio lets you know whether any issues arose with regard to resetting your settings.
If you go to Tools–Import And Export Settings–Export Settings, you’ll see the list of categories that can be contained in a .vssettings file. The first category I want to discuss is the New Project Dialog Preferred Language category.
As noted in the description, it organizes the New Project Dialog folders based on the preferred language. If C# is preferred, all the C# projects are listed at the top of the list and all the others are collected toward the bottom.
The General Development Settings use the defaults that have been familiar since the Visual Studio .NET 2002 days, as shown here:
Now let’s see the dialog box using the Visual C# Development Settings. Note how Visual Basic and Visual C++ fall into the newly created Other Languages node.
If you go to the Reset page on the Tools–Import And Export Settings Wizard, you’ll see the list of files you can reset to. These settings files are the ones created by the Visual Studio team. But, let’s say that one of the default files has some small option that just annoys you or you want to add your own file to the list, as shown here:
These files live at Program FilesMicrosoft Visual Studio 9.0Common7IDEProfiles. You’ll need administrator rights to access Program Files, so please use this tip at your own risk.
In this folder, you can add your own .vssettings files or modify the existing ones. I use the General Development Settings, but any time I do a reset, the Tools–Customize–Show Shortcut Keys In ScreenTips option becomes unchecked. This option shows you the keyboard shortcut for a toolbar button in the ToolTip, a visual cue I absolutely must have.
If you find yourself in a similar situation, where you want to make small tweaks to one of the default settings files provided, you can do the following:
The next time you reset using these settings, you’ll see your preferred settings. And in my case, I’ll see my keyboard shortcuts in my ToolTips!
Whenever I demo Tools–Import And Export Settings, I’m usually asked to explain the difference between the Import feature and the Reset feature.
From an end-user perspective, importing everything in that particular settings file provides the same functionally as a reset.
But of course, there’s more going on under the UI surface. Whenever you do a reset, the IDE stores the path of the file you picked to reset to in the registry. There are some shortcuts within the IDE to quickly reset those settings. Following are a couple of the most common of these quick reset options.
First, on the Tools–Options–Environment–Fonts And Colors page, you’ll see the Use Defaults option. This option resets your fonts and colors using the settings file you last reset to.
Second, on the Window menu, there’s the command Reset Window Layout. This command resets your window layouts (that is, all your tool windows in all four window layout states) using the settings file you last reset to.
But ... What if you attempt to reset using a file you last reset to that didn’t contain this particular category? For example, let’s say you last reset to your own settings file and it didn’t contain the Window Layouts category. Then I believe Visual Studio uses its factory defaults (the legacy settings that were built in for Visual Studio .NET 2003, the version before the Import And Export Settings feature was built) whenever you do Windows–Reset Window Layout. I recall during one of the many Profiles feature design meetings the term schizophrenia being used to describe the possible states Visual Studio could end up in. =D
Whenever you do a destructive operation via Tools–Import And Export Settings, such as importing or resetting your settings, Visual Studio prompts you to save your current settings prior to continuing. This operation is the same as doing a full export (that is, going to the Export page and checking everything to export to a file).
The one thing I’ll call out is that the Store My Settings File In This Directory combo box will remember any location where you’ve exported a file to, because you may wish to save your current settings there again in the future.
On the Tools–Options–Environment–Import And Export Settings (yes, the Tools–Import And Export Settings dialog box has its own Tools Options page), you’ll find the option that lets you choose where to store your current settings. Note that you don’t get to opt out of this. Prior to Visual Studio 2005, settings categories were saved in separate files in %appdata%, such as a file for all your toolbox customizations, your window layouts, your keyboard shortcut bindings, and your command bar changes. Starting in Visual Studio 2005, those settings are now stored in a centralized file called the CurrentSettings.vssettings file by default.
Every time Visual Studio shuts down, it writes to this file location to keep your current settings saved.
If you ever make a change that you need to quickly back out of, you can always go to Tools–Import And Export Settings–Import and choose the CurrentSettings.vssettings file, located in the My Settings folder.
This tip is more like a "tip" than my usual "micro functionality" daily tips. After you export, the final page of the wizard shows you the full file path. This page is just a read-only edit box that can take focus. In other words, you can put your cursor in it and copy the full file path.
After you export your settings, you may want to open the file and see what’s there, in case you want to make any tweaks. Otherwise, you’ll have to open the Import And Export Settings dialog box and go through the wizard to guess where you exported that file to.
Under Tools–Options–Environment–Import And Export Settings, you’ll see an option called Use Team Settings File.
This option enables you to let all the members of your team use the same baseline settings. You can provide a .vssettings file (by creating these customizations on your machine and then using Tools–Import And Export Settings–Export to create the file). Then put the .vssettings file on a Universal Naming Convention (UNC) share. Next, you check the Use Team Settings File check box, pointing it at this file.
So, what happens now? Whenever Visual Studio launches, it’ll check the time stamp of the .vssettings file, and if there has been an update, Visual Studio will reapply all the settings from the .vssettings file. But be aware, if you have any custom changes, they will be overwritten when Visual Studio detects the new team settings file.
I think that this works really well in a scenario where there’s a single developer who works on multiple computers, because any tweaks the developer makes on one machine will be carried over to the next machine.
The External Tools feature allows you to run tools that are not part of Visual Studio, such as good old notepad.exe, from within the IDE instead of having to launch the tool manually. For example, you can place a menu item to notepad.exe on the Tools menu and launch it instead of having to go to the actual location of the Notepad executable on disk.
Additionally, you can customize how these tools are launched, including providing arguments and writing information to the Output window. These tips explore what you can do with External Tools.
Let’s start with the basics. Go to Tools–External Tools to bring up the External Tools dialog box. You’ll notice a set of built-in tools ready to go for you.
This list of tools under Menu Contents maps directly to the list presented on the Tools menu, as shown here:
For this tip, let’s add Notepad as an external tool.
Go to the Tools–External Tools dialog box, and you’ll see the Add button. Click Add to create a [New Tools 1] placeholder. Rename the title by typing Notepad.
For the Command edit box, use the name of the actual executable. You should be able to just type notepad.exe, depending on your environment variables.
This is the minimum amount of information you need to include to make an external tool work. But let’s go a little further by exploring the optional arguments.
For Arguments, you can type the name of a file, either an existing file if you want Notepad to open it or the name of a file if you want Notepad to create.
For Initial Directory, you can type the file path, either the path where the filre exists or where you want Notepad to create it.
And of course, you’ll see Notepad now in the Tools menu.
We’ll explore more of the arguments and other options in the upcoming tips.
Continuing with the newly added Notepad tool from the previous tip, you can use the External Tools dialog box to sort your list of external tools as they will appear on the Tools menu. To the right of the Menu Contents list, you’ll find the Move Up and Move Down buttons.
You can specify a mnemonic, also known as a keyboard accelerator, by putting an ampersand in front of the letter to be used as the accelerator in the Title field.
Now, on the Tools menu, you can simply press n to launch Notepad.
If there’s a mnemonic conflict, the focus cycles among the commands that share that mnemonic. Then you press Enter at the appropriate command to execute the command. It is ideal to have no conflicts.
At the bottom of the External Tools dialog box, you’ll see more options for customizing the external tool within the IDE. This tip is about the Use Output Window option. The idea here is you’re running a .bat file and you want to track the progress within the IDE.
Using the command prompt as the tool, you can set Arguments to something like /C echo $(CurText), which signifies the following:
/C, from cmd.exe, carries out the command specified by the string and then terminates.
$(CurText) is a token that comes from Visual Studio that represents the currently selected text, displayed as Current Text in the menu.
Now, when running this external tool with a line of text selected in the editor, the Output window displays the text.
I’ve hinted at a few of the external tool tokens, but let’s explore a little more. Most of these are self-explanatory and are explored in depth in the documentation, but here I’ll give you a high-level overview. You can view the documentation at http://msdn2.microsoft.com/en-us/library/ekbzk5f8.aspx.
All Item and Current tokens that are available for the Arguments edit box operate on the currently active editor. Note the editor does not need to have focus to be able to work, but it must at least have inactive selection.
For the Initial Directory edit box, you’ll find all the directory tokens, but one in particular to call out is the Binary Directory. Note the Binary Directory option is new for Visual Studio 2008.
The Target Directory token targets the obj directory (objDebug), but if you need the final bits that go into the bin directory (inDebug), use the Binary Directory token.
To finish the customization of the external tools, you can check Prompt For Arguments if you need to enter or edit values each time you run the tool.
So now, if I need to specify which file I want Notepad to open, I’m prompted for the file name, which is the argument for notepad.exe.
And recall that you can set the Initial Directory, where Notepad is going to look for files.
3.143.17.27