【发布时间】:2018-08-20 16:02:55
【问题描述】:
我正在编写一个 Visual Studio 扩展,我需要创建自己的 IWpfTextViewHost(代码编辑器窗口)。这可以通过ITextEditorFactoryService 完成,但必须通过 MEF 框架加载。
但是我的导入总是null,但我似乎无法弄清楚为什么我的导入是null。我对 MEF 的工作原理有一个粗略的了解,有没有一种方法可以调用 Visual Studio 本身的CompositionContainer?还是 vsix 项目构建了这个容器?如果是,基于什么设置?
public class MyViewHost {
[Import]
public ITextEditorFactoryService TextEditorFactory { get; set; }
public IWpfTextViewHost CreateViewHost(ITextBuffer textBuffer)
{
var textView = this.TextEditorFactory.CreateTextView(textBuffer);
return this.TextEditorFactory.CreateTextViewHost(textView, true);
}
}
编辑
这是extension.vsixmanifest的相关部分
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="Build%CurrentProject%" Path="|dllName;PkgdefProjectOutputGroup|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" Path="dllName" />
</Assets>
【问题讨论】:
-
您的 .vsixmanifest 文件是什么样的?
-
您好,我在其中添加了extension.vsixmanifest的相关部分。它有一个资产作为 MefComponent
-
如何获取/创建
MyViewHost的实例?此类不实现任何已知接口,并且您不会将其导出为 MEF 组件。似乎这不是通过 MEF 组件注册表检索到的,因此无法填充导入。
标签: c# visual-studio mef visual-studio-extensions visual-studio-sdk