icclassfierprovider没有被初始化



我正试图为visual studio构建输出添加颜色。所以我试图得到IClassifierProvider的分类器。但是GetClassifier()没有被调用。有什么问题吗?源代码示例如下所示。当我尝试使用VSColorOutput扩展时,它开始启动。请告诉我我错过了什么?

 [ContentType("output")]
[Export(typeof(IClassifierProvider))]
public class OutputClassifierProvider : IClassifierProvider
{
    [Import]
    internal IClassificationTypeRegistryService ClassificationRegistry;
    [Import]
    internal SVsServiceProvider ServiceProvider;
    public static OutputClassifier OutputClassifier { get; private set; }
    public IClassifier GetClassifier(ITextBuffer buffer)
    {
        MessageBox.Show("asd");
        try
        {
            if (OutputClassifier == null)
            {
                OutputClassifier = new OutputClassifier();
            }
        }
        catch (Exception ex)
        {                
            throw;
        }
        return OutputClassifier;
    }
}
public class OutputClassifier: IClassifier
{
    public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged;
    public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
    {
            return new List<ClassificationSpan>();
    }
}

Vsix清单

<?xml version="1.0" encoding="utf-8"?>
<Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
  <Identifier Id="3ac9d6e9-a3dc-4a27-a048-f4bb7fe5889b">
    <Name>Sample</Name>
    <Author>Company</Author>
    <Version>1.0</Version>
    <Description xml:space="preserve">It conatains set of features which will ease the life of Atmel Studio user.</Description>
    <Locale>1033</Locale>
    <InstalledByMsi>false</InstalledByMsi>
    <SupportedProducts>      
      <VisualStudio Version="10.0">
        <Edition>Pro</Edition>
      </VisualStudio>
    </SupportedProducts>
    <SupportedFrameworkRuntimeEdition MinVersion="4.0" MaxVersion="4.0" />
  </Identifier>
  <References>
    <Reference Id="Microsoft.VisualStudio.MPF" MinVersion="10.0">
      <Name>Visual Studio MPF</Name>
    </Reference>
  </References>
  <Content>
    <VsPackage>XFeatures.pkgdef</VsPackage>
  </Content>
</Vsix>

谢谢Jason Malinowski我分析了清单代码,发现那里缺少MEF内容。将MEF添加到content标签后,现在可以工作了。

 <Content>
    <VsPackage>|%CurrentProject%;PkgdefProjectOutputGroup|</VsPackage>
    <MefComponent>|%CurrentProject%|</MefComponent>
  </Content>

相关内容

  • 没有找到相关文章

最新更新