Skip to content

Instantly share code, notes, and snippets.

@grokys
Created February 7, 2017 17:48
Show Gist options
  • Select an option

  • Save grokys/bc3965fbf3770a6dd70e5b7de7401f75 to your computer and use it in GitHub Desktop.

Select an option

Save grokys/bc3965fbf3770a6dd70e5b7de7401f75 to your computer and use it in GitHub Desktop.

Supporting Multiple Visual Studio Versions in a Single Package

A few people have asked how we support both Visual Studio 2015 and Visual Studio 2017 in the GitHub for Visual Studio Extension. In particular we needed to support Team Foundation 14 and 15, and we wanted to do it from a single package.

It's important to note that although each new version of Visual Studio includes all the previous versions of assemblies of many core APIs, Team Explorer is an extension and so a single version is installed.

The way we achieved this was to create two assemblies: GitHub.TeamFoundation.14 and GitHub.TeamFoundation.15. The files in the two assemblies are links to the same files, and thus identical - so how does this solve the problem?

The difference is that the two assemblies reference different versions of Microsoft.TeamFoundation.Controls and each exported MEF class implements an interface, or has an attribute, property, field or constructor parameter of a type from that assembly. When Visual Studio starts up and does its MEF scan, it loads both assemblies in reflection-only mode and scans the types contained therein. If MEF at this point can't find a referenced type, then those types won't be added to the MEF catalog and thus only a single version of each type will be registered: the one for the correct version of Visual Studio.

So if you look at the files in the GitHub.TeamFoundation.X projects you will see that each class has a reference to something in Microsoft.TeamFoundation.Controls: if this wasn't the case then two identical classes would be registered twice with MEF.

@shana
Copy link
Copy Markdown

shana commented Feb 7, 2017

it loads both assemblies in reflection-only mode and scans the types contained therein.

tbh this is me guessing as to what it's doing (and the more efficient way of doing it). I'd just say it "loads the assemblies and scans the types..."

If MEF at this point can't find a referenced type

Probably more of a "if MEF determines it can't create an instance of the type because of a missing reference". I think that other types referenced are fine, it's just stuff it needs to instantiate the type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment