Better way to load dependent assemblies in your Visual Studio extensions

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](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.providebindingpathattribute.aspx) 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!

This article is part of the GWB Archives. Original Author: Utkarsh Shigihalli

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.