I had previously written on how to load custom assemblies in your extension using AppDomain.CurrentDomain.AssemblyResolve. It required few lines of code to be written in your VS package class. Today I am going to show you an easier way of doing the same.

Visual Studio provides ProvideBindingPath`attribute which lets Visual Studio know other paths from where your extension loads the assemblies. The usage of this attribute is very simple, you just need to decorate your package class with it.

[Guid(GuidList.guidmin2015PkgString)]
[ProvideBindingPath]
public sealed class min2015Package : Package
{
}

Once you do that and compile your extension, the .pkgdef file will be modified to include a new line something like below, where {PackageGuid} will be the guid of your package.

[$RootKey$\BindingPaths\{PackageGuid}]

So, when you install the extension, along with other information, this information is also written in the registry. So when Visual Studio is loading your extension, it will also load all the assemblies from the path you have mentioned in to its app domain.

SubPath property

You can also decide to keep all your dependent assemblies in a separate folder under your extension folder. If you decide to do so, you need to mention that using SubPath property. Example below lets Visual Studio know that, the dependent assemblies are References subfolder.

[ProvideBindingPath(SubPath="References")]

That’s it for now. Happy extending Visual Studio!

Related Posts

About Utkarsh Shigihalli

Utkarsh is passionate about software development and has more than 10 years of work experience. He has developed numerous extensions for Visual Studio and Visual Studio Team Services. He is currently working as DevOps lead in one of the leading insurance company in United Kingdom