Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Professional Visual Studio 2005 (2006) [eng]

.pdf
Скачиваний:
135
Добавлен:
16.08.2013
Размер:
21.9 Mб
Скачать

Chapter 32

Once it has been located, it drills down into the menu bar object to find the object into which the add-in command will be inserted, which in this case is a CommandBarPopup object. Once it has this information and the named command has been created, you can use the command’s AddControl method to connect the command and menu.

You can use a similar method to place your command anywhere within the IDE’s collection of menus and toolbars. Simply replace the string “Tools” with the English string representing the menu you want to hook into.

CreateToolWindow2

You can even create your own tool windows that are used as part of your add-in. The CreateTool Window2 method forms the basis for creating a new tool window in the IDE, and requires that you first create a (standard) user control to be hosted inside its container space. This capability to host a user control means you can build complex user interfaces that reside within the IDE’s workspace, and they can be docked, resized, and moved just like all the other tool windows that come with Visual Studio.

Debugging

Because add-ins are created with managed code right within Visual Studio, you can use all the same debugging procedures available to you for any other Windows application. Remember that the Debug property page for the project will default to starting up an additional instance of Visual Studio 2005 and host the debugged version of the add-in in that, so if you need to test out the add-in in the Macros IDE, changing the startup settings on that page.

Refer to Section IX for more information on debugging Windows projects.

Registration and Deployment

Add-in registration is performed with the new .AddIn configuration file mentioned earlier in this chapter. Within this XML-based file you specify the various settings that control how your add-in should be loaded and which hosting applications can use it. To deploy it, simply place this .AddIn file in the Addins folder so Visual Studio 2005 can find it. You can specify that the add-in should be available to all users or a specific user by placing it in the appropriate folder. For all users, the location is \Documents and Settings\All Users\My Documents\Visual Studio 2005\Addins. Replace the All Users string with the specific user name if you want to restrict it to a particular user.

When Visual Studio 2005 starts, it will look in this folder for any add-ins that should be loaded. When it locates an .AddIn file, it reads through the XML to locate the Assembly tag, which dictates where the actual add-in DLL is to be found.

You no longer need to register your add-in through COM as you did with previous versions of Visual Studio .NET!

436

Add-Ins

Summar y

Add-ins are a great way to enhance the functionality of Visual Studio 2005 with your own unique tools. To help you get started, Microsoft provides a set of example projects you can download from their site that illustrate some of the more advanced concepts in creating complex add-ins. Go to http://msdn

.microsoft.com/downloads and search for “Visual Studio 2005 Automation Samples” to locate the current download location.

In the next chapter you’ll see how the capability to customize the functionality of Visual Studio 2005 extends beyond the use of add-ins, with an introduction to creating your own custom tools and code generators.

437

Third-Par ty Extensions

The last few chapters have discussed the concepts behind creating your own extensions to the Visual Studio 2005 IDE to address scenarios you encounter where the default toolset doesn’t do what you require. However, there is an alternative to spending time creating your own tools: download and use other people’s creations. Over the next few pages, you will see some of the best add-ins and extensions that are currently available for Visual Studio 2005.

Most of these tools are free for personal use (in fact, a lot of them are free for corporate use too). But even those you have to pay for are worth considering because they can often reduce your workload to an extent that far outweighs the small monetary investment required to use them beyond the trial period.

These tools are not owned or distributed by Microsoft. They are true third-party tools created and distributed by a variety of individuals and vendors. You are encouraged to visit the web site links provided in the description of the particular extension you’re interested in to find out more and download (and register, if necessary) the tool from the creator/vendor directly.

Development Environment Enhancements

Sometimes you’ll find yourself wishing the IDE could help you in the design of your projects and forms. While you could write a macro or more comprehensive add-in for the purpose, the two tools described here eliminate the time and effort it takes to create your own.

CoolCommands for VS2005

CoolCommands for VS2005 is a tiny set of tools that integrate directly into the IDE with no obvious interface difference. However, the small size belies two very powerful utilities that are added into the context menu of the Solution Explorer.

Chapter 33

Resolve Project References automatically attempts to check all references to other projects and assemblies from within the active project. It enables you to ensure that you have correctly identified the associated projects for your solution, and will flag any missing files for you to fix.

The other feature that makes CoolCommands for VS2005 worth including in this list is the capability to copy and paste references between projects. Simply locate the reference in the source project, right-click, and select Copy. Then open the destination project’s References folder, right-click, and select Paste. The tool will automatically add the reference correctly for you, without you needing to browse the Reference dialog to add the association.

CoolCommands for VS2005 can be downloaded from the designer’s site at http://weblogs.asp.net/ GMilano/archive/2006/02/27/439208.aspx.

MZ-Tools

MZ-Tools was first released as a free add-in for Visual Basic 6 and became one of the most popular addin toolsets for that development environment. It boasted a huge number of features, from automated control naming and tab index allocation to code sorting and generation. Now MZ-Tools is available for Visual Studio 2005 and offers even more features and improvements that will make your development life much easier, no matter what part of the IDE you normally work in

MZ-Tools has a lot going for it as a package even though the Visual Studio 2005 version must be purchased after a 30-day trial. The small set of tool windows shown in Figure 33-1 are a great example of how MZ-Tools can make form design more efficient:

Figure 33-1

440

Third-Party Extensions

The Control Explorer lists all controls currently sited on the active form layout, along with a set of commonly used properties. This enables you to quickly locate each component in the hierarchy of controls and containers and then set the properties you most often access. The Customize button gives you the capability to set which properties should be displayed.

The Control Name Assistant tool window is an even more direct way of accessing the two most commonly accessed properties on a form: Name and Text. Because often the two are related, this window updates the Name property as you change the Text property so they are kept synchronized. You can customize the control prefix in the options pages for the toolset.

The TabIndex Assistant has been part of MZ-Tools since its first release on Visual Basic 6. It provides a simple list of every control that can receive focus and its tab order. You can have MZ-Tools automatically reassign the tab order for the entire form using left to right, top to bottom logic.

Along with the many tool windows, MZ-Tools also comes with many other design-time enhancements, including the capability to customize default properties such as height and width for Button controls, and then to have those properties automatically assigned to the associated control type; an enhanced automatic control-positioning tool that aligns and positions controls on the form layout when you doubleclick them in the Toolbox; and the capability to copy all associated code (mostly in any explicitly defined event handler routines) along with a control when it is copied and pasted to another form.

Most functions are available from the toolbar, which you can customize to include only the commands you most often use (see Figure 33-2). So many options are available to you that they have been split up into Personal and Corporate options. The latter are intended to contain settings that are applied right across your company or development team, while the former include options specific to your own editing experience. Both Options screens can be accessed from the MZ-Tools toolbar or menu.

Figure 33-2

441

Chapter 33

All of the commands appear on the extra menu that MZ-Tools adds to the IDE.

The Corporate options store all the customization settings for the tools. This is where you can set control prefixes, default properties, and the definitions of a variety of code stubs that can be automatically added to your modules — from file, class, and method headers to automatic exception handlers, as shown in Figure 33-3.

Figure 33-3

These settings and commands are just the tip of the iceberg for MZ-Tools, which also includes additional functionality that can sort your code into alphabetical order, and split and rejoin lines for Visual Basic code. In addition, a set of review functions can check for improper usage of access keys or even dead code. While some of the tools replace existing functionality with a slightly different implementation (such as the Find Text dialog), they usually include additional features that you might find useful (for example, the Find Text dialog comes with much finer scope). The best way to explore everything that MZ-Tools has to offer is to try it for yourself. Download the trial version from www.mztools.com.

Code Aids

Some tools are available just to help keep your code organized or enhance the way you write it. Here are two add-ins that integrate into your code editor window.

442

Third-Party Extensions

Imports Sorter

If you liked the idea of being able to sort code, as mentioned in the MZ-Tools description, this nifty little add-in should prove useful. The Imports Sorter has a single self-explanatory purpose — to sort the Imports statements in your code into a logical order so that it is consistent across all of your projects.

Using the Imports Sorter is just as simple after you’ve installed it. Once you add the Imports statements to your code, right-click anywhere in the code window and select the new Sort the Imports Block command from the context menu (see Figure 33-4).

Figure 33-4

As shown in Figure 33-4, the sorted list isn’t in alphabetical order, but in a predefined order that makes sense — System namespaces have precedence over Microsoft namespaces, for instance. You can change the order via the Tools menu to indicate that all of your Imports code blocks will always appear in the manner specified. Download this tool from http://bordecal.mvps.org/Nicole/ImportsSorter/.

CodeKeep

The code snippet library that comes with Visual Studio 2005 is only a small set of functions that either are commonly required or illustrate lesser-known techniques. You can, of course, add your own snippets to the library, as explained in Chapter 19, but there is no easy way of sharing your snippets with other developers, or delving into their collections of code blocks for useful snippets for your own use.

CodeKeep is a utility that integrates into the Visual Studio 2005 IDE but uses a central repository on the Internet to store any code snippets you might want to keep. You first need to create a user account on the associated web site and then use those credentials when you first install the add-in.

CodeKeep enables you to submit your own snippets, search for specific keywords in the public snippet database, or simply browse the entire database by language or author (see Figure 33-5). This window is defined as a standard tool window, which means it can be docked anywhere in the IDE, providing you with quick access to the snippet library as you work.

443

Chapter 33

Figure 33-5

When you double-click a snippet entry, CodeKeep displays a detailed view of the code included in the snippet, along with description, usage, and a notes section (see Figure 33-6). This enables you to see exactly what will be included if you use the snippet. From this View Snippet dialog, you use the Copy button to copy the code into your module or class.

Figure 33-6

You can get started with CodeKeep by browsing the database of snippets and downloading the Visual Studio 2005 add-in found at www.codekeep.net.

444

Third-Party Extensions

Documentation

Documentation is an important part of the design process, and although it is provided for in Visual Studio 2005 with the inclusion of XML comment blocks, it’s still not an easy process to implement. The golden rule of “if it’s easy the developer will have more inclination to do it” means that any additional enhancements to the documentation side of development will encourage more people to use it properly.

GhostDoc is an add-in for Visual Studio that attempts to do just that, providing the capability to set up a keyboard shortcut that will automatically insert the XML comment block for a class or member. However, the true power of GhostDoc is not in the capability to create the basic stub, but to automate a good part of the documentation itself.

Through a series of lists that customize how different parts of member and variable names should be interpreted, GhostDoc will generate simple phrases that get you started in creating your own documentation. For example, consider the list shown in Figure 33-7, where words are defined as trigger points for “Of the” phrases. Whenever a variable or member name has the string “color” as part of its name, GhostDoc will attempt to create a phrase that can be used in the XML documentation. The bottom list of adjectives is used to describe the member name.

Figure 33-7

For instance, a variable name of NewBackgroundColor will generate a complete phrase of New color of the background. The functionality of GhostDoc also recognizes common parameter names and their purpose. Figure 33-8 shows this in action with a default Load event handler for a form. The sender and e parameters were recognized as particular types in the context of an event handler, and the documentation that was generated by GhostDoc reflects this accordingly.

445