VSIX 项目中的 Roslyn:无法将 ComponentModel 类型的对象转换为 IComponentModel
Roslyn in a VSIX project: Unable to cast object of type ComponentModel to IComponentModel
我一直在 VSIX 项目中试用 Roslyn。目前我要做的是加载 CurrentSolution。但是我最终遇到了错误:
Unable to cast object of type 'Microsoft.VisualStudio.ComponentModelHost.ComponentModel'
to type 'Microsoft.VisualStudio.ComponentModelHost.IComponentModel'.
我已经为 Microsoft.VisualStudio.LanguageServices 和 Microsoft.VisualStudio.ComponentModelHost 安装了 NuGet 包。
在我的 VSIX 命令包 class 的 Initialize 方法中,我添加了这个:
var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
var workspace = (Workspace)componentModel.GetService<VisualStudioWorkspace>();
这给了我提到的例外。
Microsoft.VisualStudio.ComponentModelHost DLL 的版本是 15.0.0.0。
已经尝试过:
正在删除 BIN 文件夹并重建
正在重启Visual Studio
我只是不确定是什么原因造成的,而且似乎找不到有关此错误的信息,如果能提供帮助,我们将不胜感激。
想到检查 GAC 以获取此 DLL 的版本。结果我有两个。通过 Nuget 包管理器,我安装了 15.0.0.0 版的 DLL。但我已经有一个 14.0.0.0 版本(不确定它来自哪里)。我从 GAC 和我的项目的引用中删除了 15.0.0.0,然后添加了现有的 14.0.0.0 引用。现在铸造没有问题。
我一直在 VSIX 项目中试用 Roslyn。目前我要做的是加载 CurrentSolution。但是我最终遇到了错误:
Unable to cast object of type 'Microsoft.VisualStudio.ComponentModelHost.ComponentModel'
to type 'Microsoft.VisualStudio.ComponentModelHost.IComponentModel'.
我已经为 Microsoft.VisualStudio.LanguageServices 和 Microsoft.VisualStudio.ComponentModelHost 安装了 NuGet 包。
在我的 VSIX 命令包 class 的 Initialize 方法中,我添加了这个:
var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
var workspace = (Workspace)componentModel.GetService<VisualStudioWorkspace>();
这给了我提到的例外。
Microsoft.VisualStudio.ComponentModelHost DLL 的版本是 15.0.0.0。
已经尝试过:
正在删除 BIN 文件夹并重建
正在重启Visual Studio
我只是不确定是什么原因造成的,而且似乎找不到有关此错误的信息,如果能提供帮助,我们将不胜感激。
想到检查 GAC 以获取此 DLL 的版本。结果我有两个。通过 Nuget 包管理器,我安装了 15.0.0.0 版的 DLL。但我已经有一个 14.0.0.0 版本(不确定它来自哪里)。我从 GAC 和我的项目的引用中删除了 15.0.0.0,然后添加了现有的 14.0.0.0 引用。现在铸造没有问题。