We recommend using Visual Studio 2017

Part 2: Tangential Topics

 

In the second part of this booklet, we survey two important (and unrelated) tangential topics: customizing Visual Studio .NET's New Project dialog box by means of the registry and Visual Studio .NET add-ins.

Customizing the New Project Dialog Box
Visual Studio.NET Add-Ins

Customizing the New Project Dialog Box

In practice, Enterprise Templates are often coupled with the customization of the Visual Studio .NET environment. In this section, we offer an example of the latter.

Refer back to Figure 3. and you will see that your template icon appears in the Other Projects\Enterprise Template Projects folder of the New Project dialog box. In a real-world scenario, it might be preferable to have the icon appear in its own folder as opposed to this obscure location. The following steps create a custom folder in the New Project dialog box by means of some file manipulation and registry settings.

Recall that in part 1 of the booklet you created a file named MyUserTemplate.vsdir within the following directory:

C:\Program Files\Microsoft Visual Studio .NET
  2003\EnterpriseFrameworks\ProxyProjects

It is this .vsdir file that embeds the template icon in the New Project dialog box.

To create a custom folder in the New Project dialog box

  1. Navigate to the aforementioned directory with the Windows Explorer.
  2. Right-click the right pane of Windows Explorer (where the files are listed), point to New, and select Folder.

    A folder named New Folder is created for you.

  3. Rename the folder MyTemplateFolder.
  4. Copy the MyUserTemplate.vsdir file from the following directory:
    ..\%VSNETRoot%\EnterpriseFrameworks\ProxyProjects
    
    

    to the following directory:

    ..\%VSNETRoot%\EnterpriseFrameworks\ProxyProjects\MyTemplateFolder
    
    
  5. Delete the MyUserTemplate.vsdir file from the ..\%VSNETRoot%\EnterpriseFrameworks\ProxyProjects directory.
  6. The MyUserTemplate.vsdir file must be modified to reflect its new location. Using NOTEPAD, open it from its new directory, …\EnterpriseFrameworks\ProxyProjects\MyTemplateFolder, and add ..\ to the beginning of the first line. In other words, the first line should now look like:
    ..\..\Projects\MyTemplate\MyTemplate.etp|{AE77B8D...
    
    

    instead of:

    ..\Projects\MyTemplate\MyTemplate.etp|{AE77B8D...
    
    

Before you can add the appropriate entries to the registry to enlist your new folder with Visual Studio .NET, you must first generate a Globally Unique Identifier (GUID). A GUID is a 128-bit unique number that is often used by Windows Applications to identify unique entities such as components, files, and resources.

To generate a GUID on the system

  1. Point to the Start menu, then Programs, then Microsoft Visual Studio .NET 2003, then Visual Studio .NET Tools, then Visual Studio .NET 2003 Command Prompt (Figure 21).

    Aa302170.vsent_enterprisetemplatesbk21(en-us,MSDN.10).gif

    Figure 21. The Visual Studio .NET 2003 Command Prompt

  2. Type "guidgen" at the Command Prompt and press Enter. This launches the GUIDGEN utility, which will generate custom GUIDs for you.
  3. Click the New GUID button, and then click the fourth radio button to store the GUID in a format appropriate for the registry (Figure 22).

    Aa302170.vsent_enterprisetemplatesbk22(en-us,MSDN.10).gif

    Figure 22. The GUIDGEN Utility

  4. Click the Copy button in the GUIDGEN utility.
  5. Close the GUIDGEN utility.

    You have now generated a GUID that can be used to represent your custom folder to Visual Studio .NET. The last remaining step is to make the appropriate registry entries.

  6. Point to the Start menu, and then click Run.
  7. Type "regedit" at the Run dialog box, which will launch the Windows Registry Editor.
  8. Navigate to the following registry folder, which maintains a list of those folders that Visual Studio .NET lists in the New Project dialog box:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\NewProjectTemplates
      \TemplateDirs
    
    
  9. Right-click the TemplateDirs folder, point to New. and click Key.

    A key named New Key is added to the folder.

  10. Press CTRL-V and press ENTER to rename the key to the GUID value you copied in the GUIDGEN utility.
  11. Right-click the folder you just renamed, point to New and click Key.
  12. A key named New Key is added to the folder.
  13. Rename the key "/1."
  14. Right-click the "/1" folder you just created, point to New, and click DWORD value.

    A key named New Value #1 is added to the right pane of the editor.

  15. Rename the key SortPriority.
  16. Once again, right-click the "/1" folder, point to New and click String value.

    A key named New Value #1 is added to the right pane of the editor.

  17. Rename the key TemplatesDir.
  18. Double-click the TemplatesDir key in the right pane of the editor.
  19. The Edit String dialog box appears, which allows you to give the key a value.
  20. Give the key the following value (where C:\ is the drive where Visual Studio .NET is installed).
    C:\Program Files\Microsoft Visual Studio .NET
      2003\EnterpriseFrameworks\ProxyProjects\MyTemplateFolder
    
    
  21. On the right pane of the editor, there is a final key named Default; double-click it.
  22. The Edit String dialog box appears; give the key a value of MyTemplateFolder.

    A sample of the final registry settings you should have is shown in Figure 23 (note that your GUID key name will differ).

    Click here for larger image

    Figure 23. Final registry settings

    Note   You do not have to give the SortPriority key a value since it defaults to 0 when you create it. This value results in the folder being displayed first in the New Project dialog box.

To test your changes

  1. Close Visual Studio .NET 2003 if it is open.
  2. Open Visual Studio .NET 2003.
  3. On the File menu, point to New, and then click Project.

    The New Project dialog box appears.

    As illustrated in your new folder, MyTemplateFolder appears in the left pane of the dialog box, whereas the available project types (MyTemplate) appear in the right pane.

    Aa302170.vsent_enterprisetemplatesbk24(en-us,MSDN.10).gif

    Figure 24. The modified New Project dialog

Visual Studio.NET Add-Ins

Enterprise Templates are useful in prescribing the Visual Studio .NET environment when a certain solution type is created. As you have seen, you can restrict the environment by means of policy, and even add custom help content by way of Just in Time Guidance. There are times, however, when your requirements may be more demanding. For example, you might wish to write custom code that runs within and interacts with the IDE (for example, custom syntax color highlighting or a special spell checker). In fact, the Enterprise Template Policy editor we illustrated earlier (Figure 8) was written as a Visual Studio .NET add-in.

A Visual Studio .NET add-in is exactly that: an application that attaches to and is accessible from within the IDE. In this way, an add-in is somewhat like a macro, in that it allows code to execute within the confines of the Visual Studio .NET environment. Unlike macros, add-ins have the added benefit of being compiled applications so that distributing the source code is not required. Further, because add-ins are written in full-fledged languages such as C# and C++ (unlike Macros that are written in Visual Basic for Applications), they can carry out complicated tasks very quickly.

One of the most ironic (and confusing) aspects of Microsoft's new development environment is its underlying technology. Although Visual Studio .NET produces .NET applications, the product itself is written primarily in Microsoft's older technology: COM (Component Object Model). Visual Studio .NET add-ins, therefore, must be written in any language capable of adhering to the COM standard. All add-ins must implement a special COM interface called IDTExtensibility2 and communicate with the IDE through an automation object model contained within the EnvDTE type library (dte.olb). In addition, if an add-in is to be accessed from the environment's Tools menu, it must implement the IDTCommandTarget interface, and finally, implement the IDTToolsOptionPage interface to have an option page (separate screen) within the IDE.

The Component Object Model is a complex and cryptic technology (and thus was eradicated completely within the .NET Framework itself). One way to write an add-in is to use the "native" technologies, such as Visual C++ and the Active Template Library (ATL). A second technique is to use .NET languages, such as VB.NET and C#, coupled with Microsoft's Reverse COM Interop technology, which allows .NET applications to interact with COM. Both approaches are supported by way of Visual Studio .NET's add-In template, illustrated in Figure 1.25.

Aa302170.vsent_enterprisetemplatesbk25(en-us,MSDN.10).gif

Figure 25. The add-in template

For projects created with the template in Figure 25, Visual Studio .NET generates the appropriate COM boilerplate code, which consists of empty method definitions for which you provide the code. Create a project of this type, and you will find methods such as OnAddInsUpdate(), OnBeginShutDown(), OnConnection(), OnDisconnection(), which are called during certain periods in the add-in's lifetime. A thorough examination of these methods and general workings of add-ins is beyond the scope of this book. For more information, consult the MSDN.

Show: