C# 从类.NET核心导出接口
我有一些代码在使用.NET时可以正常工作,但是当代码被移植到开始使用.NET内核时,我再也无法导出下面的接口,并且出现错误 找不到类型或命名空间名称“ExportAttribute”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 :
// 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
)一起包含。导出属性的完整命名空间是什么?您添加了对的引用了吗?