实体框架设计器扩展未加载

时间:2012-02-03 20:27:04

标签: visual-studio-2010 vsix visual-studio-extensions entity-framework-designer

我为EF设计器创建了一个小扩展,为属性窗口添加了一个新属性。我使用vsix项目(新项目 - > c# - > extensibility - > vsix项目)完成了这项工作。当我点击F5时,实验VS实例启动。我创建了一个新项目,添加了一个实体数据模型并添加了一个实体。但是,我的破发点永远不会被击中,我看不到属性。关于我可能做错什么的任何想法?

public class AggregateRootValue
{
    internal static XName AggregateRootElementName = XName.Get("AggregateRoot", "http://efex");

    private readonly XElement _property;
    private readonly PropertyExtensionContext _context;

    public AggregateRootValue(XElement parent, PropertyExtensionContext context)
    {
        _property = parent;
        _context = context;
    }

    [DisplayName("Aggregate Root")]
    [Description("Determines if an entity is an Aggregate Root")]
    [Category("Extensions")]
    [DefaultValue(true)]
    public string AggregateRoot 
    {
        get 
        {
            XElement child = _property.Element(AggregateRootElementName);
            return (child == null) ? bool.TrueString : child.Value;
        }
        set 
        {
            using (EntityDesignerChangeScope scope = _context.CreateChangeScope("Set AggregateRoot"))
            {
                var element = _property.Element(AggregateRootElementName);
                if (element == null)
                    _property.Add(new XElement(AggregateRootElementName, value));
                else
                    element.SetValue(value);
                scope.Complete();
            }
        }
    }
}

[Export(typeof(IEntityDesignerExtendedProperty))]
[EntityDesignerExtendedProperty(EntityDesignerSelection.ConceptualModelEntityType)]
public class AggregateRootFactory : IEntityDesignerExtendedProperty
{
    public object CreateProperty(XElement element, PropertyExtensionContext context)
    {
        var edmXName = XName.Get("Key", "http://schemas.microsoft.com/ado/2008/09/edm");
        var keys = element.Parent.Element(edmXName).Elements().Select(e => e.Attribute("Name").Value);

        if (keys.Contains(element.Attribute("Name").Value))
            return new AggregateRootValue(element, context);

        return null;
    }
}

编辑:我把代码放在Github上:https://github.com/devlife/Sandbox

编辑:按照建议将MEF组件添加到清单后,扩展程序仍然永远不会加载。这是清单的图片:

VSIX Manifest

3 个答案:

答案 0 :(得分:2)

事实证明,答案就在于我如何设置我的项目。我将两个类放在生成VSIX文件的项目中。通过简单地将这些类移动到另一个项目中并将该项目设置为清单中的MEF组件(从而复制组件),它就像一个魅力!

答案 1 :(得分:1)

对于VS2012,只需添加Solution作为MEF组件。只需将整个解决方案添加为MEF组件。 然后它的效果非常好。

enter image description here

答案 2 :(得分:0)

您的项目构建的dll似乎不会自动包含在生成的VSIX包中,并且VS2013不会通过IDE为您提供更改此选项的选项(无论如何我都可以解决)。

您必须手动打开项目文件并更改XML。要更改的属性是IncludeAssemblyInVSIXContainer。

见到这里:How to include VSIX output in it's package?