VSIX 项目:由于转换问题无法获取当前工作区
VSIX-Project: Unable to get current Workspace due to casting issues
我正在尝试为 vs2017 构建一个 VSIX 包,以使自定义工具可用。
我现在面临的问题是调试时无法获取当前工作区。
以下代码用于获取工作空间:
var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
var workspace = (Workspace)componentModel.GetService<VisualStudioWorkspace>();
第二行代码抛出的错误是"Unable to cast object of type 'Microsoft.VisualStudio.LanguageServices.RoslynVisualStudioWorkspace' to type 'Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace'.".
我已经按照其他线程的建议将语言服务包添加到项目中。
如果您加载了两个不同版本的 Roslyn DLL(您可以在“调试”、“模块”中检查),就会发生这种情况。
确保您的 VSIX 项目中对 Roslyn 的引用未设置为复制本地或包含在 VSIX 中。
我正在尝试为 vs2017 构建一个 VSIX 包,以使自定义工具可用。 我现在面临的问题是调试时无法获取当前工作区。 以下代码用于获取工作空间:
var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));
var workspace = (Workspace)componentModel.GetService<VisualStudioWorkspace>();
第二行代码抛出的错误是"Unable to cast object of type 'Microsoft.VisualStudio.LanguageServices.RoslynVisualStudioWorkspace' to type 'Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace'.".
我已经按照其他线程的建议将语言服务包添加到项目中。
如果您加载了两个不同版本的 Roslyn DLL(您可以在“调试”、“模块”中检查),就会发生这种情况。
确保您的 VSIX 项目中对 Roslyn 的引用未设置为复制本地或包含在 VSIX 中。