如何从 VisualStudioWorkspace 获取工作区? [英] How to get workspace from VisualStudioWorkspace?
问题描述
我正在尝试从 Visual Studio 获取 Workspace,以便与 roslyn 一起使用.
I'm trying to get Workspace from visual studio to use it with roslyn.
我找到了一些关于这个的话题,比如这个:如何从 IVsSolution 获取对Roslyn"工作区对象的引用?
I found some topics about that, like this one : How to get reference to 'Roslyn' Workspace object from IVsSolution?
我写了完全相同的代码:
I wrote exactly the same code :
var componentModel = (IComponentModel)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SComponentModel));
var workspace = componentModel.GetService<Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace>();
但我收到此错误...
"没有找到与约束匹配的导出:ContractNameMicrosoft.CodeAnalysis.Workspace RequiredTypeIdentityMicrosoft.CodeAnalysis.Workspace"
"No exports were found that match the constraint: ContractName Microsoft.CodeAnalysis.Workspace RequiredTypeIdentity Microsoft.CodeAnalysis.Workspace"
我真的不明白这是什么问题.
I don't really understand what's the problem.
推荐答案
听起来 Roslyn 语言服务并未在 Visual Studio 的实验版本中运行.您必须从这里下载最终用户预览:http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx
Sounds like the Roslyn language services aren't running in the experimental version of Visual Studio. You have to download the end user preview from here: http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx
其中包括一个名为将 Roslyn Preview 安装到 Roslyn Experimental Hive"的程序,您必须运行该程序.
That includes a program called "Install Roslyn Preview into Roslyn Experimental Hive" that you must run.
您正在运行的 VSPackage 必须具有命令行参数/rootSuffix Roslyn".您可以通过右键单击解决方案资源管理器中的项目,单击属性并导航到调试"来设置.
The VSPackage you're running must have the command line arguments "/rootSuffix Roslyn". You can set this by right clicking the project in Solution Explorer, clicking properties and navigating to "Debug".
最后,您必须在 .csproj XML 文件中包含一个额外的属性:
Lastly, you must include an extra property in the .csproj XML file:
<VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix>
在我之前的问题中有一个解释:将 VsPackage 附加到 Roslyn 实例
There's an explanation in a previous question of mine: Attach VsPackage to Roslyn Instance
这篇关于如何从 VisualStudioWorkspace 获取工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!