Export (0) Print
Expand All

How to: Register and Manage Feature Extensions

You can add custom types and targets for refactoring, rules for analyzing database code, conditions for database unit tests, and data generators to increase the functionality that Visual Studio Premium or Visual Studio Ultimate offer. However, you must first register a feature extension before you can use it, whether you created the extension or you installed one that someone else created. For more information, see Extending the Database Features of Visual Studio.

As a best practice, you should create a folder for your extensions inside the Program Files\Microsoft Visual Studio 10.0\VSTSDB\Extensions folder. By taking this approach, you can grant write permissions to the subfolder but not to the Extensions folder itself. Users can then add custom extensions but not accidentally change the files that are part of Visual Studio.

Caution noteCaution

You must have administrator permissions on your computer to create a subfolder in the Program Files\Microsoft Visual Studio 10.0\VSTSDB\ folder. If you do not have the appropriate permissions, contact your network administrator.

Security Considerations

Before you install an extension that you did not create, you should understand the following risks:

  • The installation program for the extension might be malicious and gain access to protected resources based on your installation permissions.

  • The extension itself might be malicious and gain control of protected resources if the user who uses the extension has sufficient permissions.

To minimize your risk, you should install an extension only if it is from a known source. If you obtain an extension from an untrusted source, you should inspect the source code for that extension and its installation program (if it has one) before you install and use the extension.

To install a custom feature extension

  • Copy the signed assembly (.dll) to the Program Files\Microsoft Visual Studio 10.0\VSTSDB\Extensions\CustomExtensions folder.

    CustomExtensions is the name of the folder that you or your computer administrator created to contain assemblies and XML files for feature extensions.

    NoteNote

    As a best practice, you should not copy your assemblies and XML files directly into the Program Files\Microsoft Visual Studio 10.0\VSTSDB\Extensions folder. If you instead use a subfolder, you prevent accidental changes to the files that are provided with Visual Studio.

    Next, you must register the extension so that it will appear in Visual Studio.

To register a feature extension

  1. On the View menu, click Other Windows, and then click Command Window.

  2. In the Command window, type the following code, and substitute the path and the file name of the assembly for FilePath. Include the quotation marks around the path and the file name.

    NoteNote

    If you created an extension, the default path of the compiled .dll file is YourSolutionPath\bin\Debug or YourSolutionPath\bin\Release.

    ? System.Reflection.Assembly.LoadFrom("FilePath").FullName
    

    ? System.Reflection.Assembly.LoadFrom(@"FilePath").FullName
    

  3. Press Enter.

  4. Copy the resultant line to the Clipboard. The line should resemble the following:

    "GeneratorAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nnnnnnnnnnnnnnnn"
    
  5. Open a plain-text editor, such as Notepad.

  6. Provide the following information, specifying your own assembly name, public key token, and extension type:

    <?xml version="1.0" encoding="utf-8" ?>
    <extensions assembly=""
                version="1" xmlns="urn:Microsoft.Data.Schema.Extensions"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:schemaLocation="urn:Microsoft.Data.Schema.Extensions Microsoft.Data.Schema.Extensions.xsd">
      <extension type="<enter extension type here>" assembly="<enter assembly name here>, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b4deb9b383d021b0" enabled="true"/>
    </extensions>
    

    The extension type is of the form "namespace.classname". The assembly name does not contain the .dll extension.

    TipTip

    The file can contain a list of extension types if your assembly has multiple classes.

  7. Save the file with the .Extensions.xml file name extension.

    For example, you could name the file TestConditionName.Extensions.xml.

  8. Add this file to the Program Files\Microsoft Visual Studio 10.0\VSTSDB\Extensions\CustomExtensions folder.

    CustomExtensions is the name of the folder that you or your computer administrator created to contain the assemblies and XML files for feature extensions.

    NoteNote

    As a best practice, you should not copy your assemblies and XML files directly into the Program Files\Microsoft Visual Studio 10.0\VSTSDB\Extensions folder. If you instead use a subfolder, you prevent accidental changes to the files that are provided with Visual Studio.

  9. Close and re-open Visual Studio.

    The extension is now available.

The following example shows the XML file that is required to register the custom database code analysis rule that is created in Walkthrough: Authoring a Custom Static Code Analysis Rule Assembly for SQL. You must substitute your own public key and assembly name. The assembly name in the following example is "SampleRules".

<?xml version="1.0" encoding="utf-8"?>
<extensions assembly=""
            version="1" xmlns="urn:Microsoft.Data.Schema.Extensions"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="urn:Microsoft.Data.Schema.Extensions Microsoft.Data.Schema.Extensions.xsd">
  <extension type="SampleRules.AvoidWaitForDelayRule" assembly="SampleRules, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b4deb9b383d021b0" enabled="true"/>
</extensions>

Community Additions

ADD
Show:
© 2014 Microsoft