Search code examples
visual-studiovisual-studio-extensions

Visual Studio 2015 fail to load package because Microsoft.VisualStudio.Shell.15.0 fail to load


I've built a Visual Studio extension for Visual Studio 2015 and 2017. I've developed it with 2017 and everything works great on 2017.

When I install it on VS 2015 I get an error message saying it failed to load my package. In the visual studio ActivityLog.xml file I see the following error.

How can I enable both VS 2015 and 2017 to run the extension?

CreateInstance failed for package [MainWindowPackage]
Source: 'mscorlib' 
Description: Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. 

File name: 'Microsoft.VisualStudio.Shell.15.0, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type) at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase) at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo) at System.AppDomain.CreateInstanceFrom(String assemblyFile, String typeName) 

Solution

  • According to the error message, your extension dependency on Microsoft.VisualStudio.Shell.15.0, which is a VS 2017 assembly. So it is not contained in your VS 2015.

    If you want your extension supports multiple versions of Visual Studio, you need to let your VSPackage to using only the features of the earliest version of Visual Studio that you support and program your VSPackage to adapt to the version of Visual Studio in which it is running. You could read this document: https://learn.microsoft.com/en-us/visualstudio/extensibility/choosing-between-shared-and-versioned-vspackages

    And you also could reference the document that Supporting Multiple Versions of Visual Studio.

    The custom installation path is "C:\Users\UserName\AppData\Local\Microsoft\VisualStudio\14.0\Extensions\". Please check your extension path to make sure the Microsoft.VisualStudio.Shell.15.0 is installed.