Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从类.NET核心导出接口_C#_.net - Fatal编程技术网

C# 从类.NET核心导出接口

C# 从类.NET核心导出接口,c#,.net,C#,.net,我有一些代码在使用.NET时可以正常工作,但是当代码被移植到开始使用.NET内核时,我再也无法导出下面的接口,并且出现错误 找不到类型或命名空间名称“ExportAttribute” // Interface.cs public interface IModule { string name { get; } } // TestModule.cs [Export ( typeof ( IModule ) )] public class TestModule :

我有一些代码在使用.NET时可以正常工作,但是当代码被移植到开始使用.NET内核时,我再也无法导出下面的接口,并且出现错误

找不到类型或命名空间名称“ExportAttribute”

// Interface.cs
public interface IModule {
    string name {
        get;
    }
}

// TestModule.cs
[Export ( typeof ( IModule ) )]
public class TestModule : IModule {
}

出口线怎么了?在.NET核心中不允许这样做吗?

ExportAttribute
是MEF(托管扩展性框架)的一部分。在完整的.NET中,它包含在作为.NET框架本身一部分的
System.ComponentModel.Composition
dll中


在.NET内核中,它包含在
System.Composition.AttributeModel
nuget包中。因此,请安装,它将作为
System.Composition.ExportAttribute
提供。或者最好只安装
System.Composition
包,该包将上述包作为依赖项与其他必要的MEF类(例如
CompositionHost
)一起包含。

导出属性的完整命名空间是什么?您添加了对的引用了吗?