How to package a VSIX-based extension for multiple Visual Studio versions?

You may:

  1. decouple the functionality exposed by the two version-specific assemblies into an ad-hoc interface (which you can put itself into the host assembly, if you wish), as you may do with every other MEF plugin; let's call it IDoWork;
  2. implement the aforementioned interface in two concrete types, exposed by two different assemblies, one for each VS version you are supporting, e.g. DoWorkVs2010 and DoWorkVs2012;

    • AssemblyForVS2010.dll -> DoWorkVs2010 : IDoWork
    • AssemblyForVS2012.dll -> DoWorkVs2012 : IDoWork

. 3. (optional) [Export] the two types, to make them available through MEF; e.g.:

    [Export(typeof(IDoWork))]
    class DoWorkVs2010 : IDoWork
    {
        // ...
    }

4. add a factory to your host assembly (the one loaded directly with your VSX) and, from there, build the concrete type you are looking for, based on the DTE version:

    static class DoWorkFactory
    {
        internal static IDoWork Build()
        {
            // Load the version-specific assembly

            // - Via reflection (see http://stackoverflow.com/a/465509/904178)
            // - Or via MEF

            return ...;
        }
    }