我正在编写一个VS 2012插件,其中包含一个Package
以及一个IWpfTextViewCreationListener
MEF
扩展类。Visual Studio扩展MEF类未通过MSI安装时实例化
它使用WiX项目创建的MSI进行安装,将所有文件放置在C:\Program Files\...[Application]
;它创建Packages注册表项以指向包含Package实现的DLL。
在实验性Visual Studio实例中调试插件时,所有内容都正常运行。
运行MSI安装程序时,程序包代码运行正常,但未实例化MEF类。
注意:如果我使用VSIX(我不用于MSI安装)安装软件包,一切都正常。
的MEF类(在相同的集合作为包装):
[Export(typeof (IWpfTextViewCreationListener))]
[ContentType("text")]
[TextViewRole(PredefinedTextViewRoles.Document)]
internal sealed class HighlightAdornerFactory : IWpfTextViewCreationListener
{
[Import]
public IClassificationTypeRegistryService ClassificationRegistry = null;
[Import]
public IClassificationFormatMapService FormatMapService = null;
[Export(typeof (AdornmentLayerDefinition))]
[Name(HighlightAdornment.Name)]
[Order(After = PredefinedAdornmentLayers.Selection, Before = PredefinedAdornmentLayers.Text)]
public AdornmentLayerDefinition editorAdornmentLayer = null;
public void TextViewCreated(IWpfTextView textView)
{ /** ... **/ }
}
我以前VisualMEFX
检查,这是打包在DLL据报道,没有出口匹配IClassificationTypeRegistryService
。这并不能解释为什么当它与VSIX一起安装时,或者通过IDE进行调试。但是在解决问题时可能很有用。
[Export] MySolution.HighlightAdornerFactory (ContractName="Microsoft.VisualStudio.Text.Editor.IWpfTextViewCreationListener")
[Export] MySolution.Adornment.HighlightAdornerFactory.editorAdornmentLayer (ContractName="Microsoft.VisualStudio.Text.Editor.AdornmentLayerDefinition")
[Import] MySolution.Adornment.HighlightAdornerFactory.ClassificationRegistry (ContractName="Microsoft.VisualStudio.Text.Classification.IClassificationTypeRegistryService")
[Exception] System.ComponentModel.Composition.ImportCardinalityMismatchException: No exports were found that match the constraint:
ContractName Microsoft.VisualStudio.Text.Classification.IClassificationTypeRegistryService
RequiredTypeIdentity Microsoft.VisualStudio.Text.Classification.IClassificationTypeRegistryService
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition)
at Microsoft.ComponentModel.Composition.Diagnostics.CompositionInfo.AnalyzeImportDefinition(ExportProvider host, IEnumerable`1 availableParts, ImportDefinition id) in C:\Temp\MEF_Beta_2\Samples\CompositionDiagnostics\Microsoft.ComponentModel.Composition.Diagnostics\CompositionInfo.cs:line 157
[Import] MySolution.HighlightAdornerFactory.FormatMapService (ContractName="Microsoft.VisualStudio.Text.Classification.IClassificationFormatMapService")
[Exception] System.ComponentModel.Composition.ImportCardinalityMismatchException: No exports were found that match the constraint:
ContractName Microsoft.VisualStudio.Text.Classification.IClassificationFormatMapService
RequiredTypeIdentity Microsoft.VisualStudio.Text.Classification.IClassificationFormatMapService
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition)
at Microsoft.ComponentModel.Composition.Diagnostics.CompositionInfo.AnalyzeImportDefinition(ExportProvider host, IEnumerable`1 availableParts, ImportDefinition id) in C:\Temp\MEF_Beta_2\Samples\CompositionDiagnostics\Microsoft.ComponentModel.Composition.Diagnostics\CompositionInfo.cs:line 157
我已经尝试从我的程序集中添加所有引用的库到MSI,但这没有帮助。我没有看到任何例外情况,IWpfTextViewCreationListener
类完全没有加载。
谢谢杰森。我昨天晚上发现了wix VsixPackage元素,并且会给你一个镜头。我很欣赏这种回应。 –