Visual Studio 2015无法加载程序包,因为Microsoft.VisualStudio.Shell.15.0无法加载。

7

我已经为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) 
2个回答

7
根据错误信息,您的扩展依赖于 Microsoft.VisualStudio.Shell.15.0,它是一个 VS 2017 组件。因此它不包含在您的 VS 2015 中。
如果您希望您的扩展支持多个版本的 Visual Studio,则需要让您的 VSPackage 仅使用您支持的最早版本的 Visual Studio 的功能,并编写您的 VSPackage 以适应它所运行的 Visual Studio 版本。您可以阅读此文档:https://learn.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\14.0\Extensions\"。请检查您的扩展路径以确保已安装 Microsoft.VisualStudio.Shell.15.0。

3

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接