如何从 VS 包中获取 Roslyn 工作区? [英] How do I get a Roslyn workspace from a VS package?

查看:38
本文介绍了如何从 VS 包中获取 Roslyn 工作区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Visual Studio 2015 CTP5 包中获取当前的 Roslyn 工作区?

From a Visual Studio 2015 CTP5 package, how do I get the current Roslyn workspace?

我看了

如何获取对Roslyn"工作区的引用来自 IVsSolution 的对象?

Roslyn:如何获得从当前加载的解决方案对 Workspace 的引用?

但我仍然无法让它工作:

but I still can't make it work:

Workspace.CurrentWorkspace 不再存在

Workspace.CurrentWorkspace does not exist anymore

我已尝试导入 VisualStudioWorkspace,但它仍然为空:

I have tried importing the VisualStudioWorkspace but it is still null:

public sealed class VSPackage1Package : Package
{
 ....
    [Import]
    public VisualStudioWorkspace Workspace { get; set; }
 ....   
    protected override void Initialize()
    {
    // Workspace is null here...

某处有样品吗?

推荐答案

我没有看到 VisualStudioWorkspace(或 Microsoft.VisualStudio.LanguageServices 程序集)的任何定义

I don't see any definition of VisualStudioWorkspace (or the Microsoft.VisualStudio.LanguageServices assembly)

它就在那里,请仔细检查您找对地方了.

It's there, double check you're looking in the right place.

[Import] 仅在您使用的类本身是 MEF 导出时才有效.如果不是(比如你的包),只需写:

[Import]s only work if the class you're working in itself is MEF exported. If it's not (like a Package in your case), just write:

var componentModel = (IComponentModel)GetService(typeof(SComponentModel));
var workspace = componentModel.GetService<VisualStudioWorkspace>();

这篇关于如何从 VS 包中获取 Roslyn 工作区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆