This documentation is archived and is not being maintained.

How to: Load Dependent Assemblies

Visual Studio 2010

If the main assembly in an extension depends on a helper assembly, you must specify the path of the directory in which the helper assembly is located. This path will be added to the paths that Visual Studio uses to find dependent assemblies. This requirement applies to both VSPackages and Managed Extensibility Framework (MEF) extensions.

Security noteSecurity Note

Visual Studio adds all the paths registered in this way to its permanent list of paths for assembly resolution. Therefore, we recommend that you include all your code in a single assembly, and use this loading technique only as a last resort. Moreover, when you use this attribute, you cannot specify the full path of the helper assembly; you can specify only the directory. This means that Visual Studio will load all of the assemblies that it finds there, including assemblies that may have been added by other users or processes and may not be secure.

To specify a location for helper assemblies

  • Find the ProvideBindingPathAttribute.cs file in the ...\VisualStudioIntegration\Common\Source\CSharp\RegistrationAttributes\ directory and then add a copy of it to your extension project.In the VSPackage class in your extension project, add the ProvideBindingPath attribute. If your extension does not include a VSPackage, then add the attribute to any public class.

    [ProvideBindingPath]
    

    This attribute causes the CreatePkgDef utility to add the following line to the .pkgdef file,

    [$RootKey$\BindingPaths\{<GUID>}]
    

    where <GUID> is the GUID of the VSPackage, if there is one, or the GUID of the class to which you added the attribute. If the class does not have a GUID attribute, you can add one that has a randomly-generated GUID. The binding path algorithm uses the GUID only for identification.

If you want to install helper assemblies in a subdirectory of the extension installation directory, add the SubPath parameter to the ProvideBindingPath attribute.

To specify a subpath of the extension installation directory as the dependent assembly path

  • Specify a subpath, for example, for a subdirectory named \Assemblies\, as follows.

    [ProvideBindingPath(SubPath="Assemblies")]
    

    The CreatePkgDef utility then adds the following lines to your .pkgdef file.

    [$RootKey$\BindingPaths\{EABFA8F0-44BE-463A-9EAD-5D9700CDB8A4}]
    "$PackageFolder$\\Assemblies"=""
    
    

    To specify multiple paths, add this attribute once for each of them.

Show: