Visual Studio 2015 加载包失败,因为 Microsoft.VisualStudio.Shell.15.0 加载失败

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

我为 Visual Studio 2015 年和 2017 年构建了一个 Visual Studio 扩展。我在 2017 年开发了它,在 2017 年一切正常。

当我在 VS 2015 上安装它时,我收到一条错误消息,说它无法加载我的包。在 visual studio ActivityLog.xml 文件中,我看到以下错误。

如何启用 VS 2015 和 2017 以 运行 扩展?

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) 

根据错误消息,您的扩展依赖于 Microsoft.VisualStudio.Shell.15.0,这是一个 VS 2017 程序集。所以它不包含在你的 VS 2015 中。

如果您希望您的扩展支持多个版本的 Visual Studio,您需要让您的 VSPackage 仅使用 最早版本的 Visual Studio 的功能] 你支持和编程你的 VSPackage 以适应它是 运行 的 Visual Studio 版本。您可以阅读此文档:https://docs.microsoft.com/en-us/visualstudio/extensibility/choosing-between-shared-and-versioned-vspackages

您也可以参考 Supporting Multiple Versions of Visual Studio.

的文档

自定义安装路径为"C:\Users\UserName\AppData\Local\Microsoft\VisualStudio.0\Extensions\"。请检查您的扩展路径以确保 Microsoft.VisualStudio.Shell.15.0 已安装。

您应该在扩展中引用 Microsoft.VisualStudio.Shell.14.0 和 VS 2015 中的其他程序集以支持 VS 2015/2017。