.net – 如何在Portable类库中使用MEF?

我有可移植的类库,目标是.NET 4.5和
Windows Store App.
According to MSDN this setting should offer MEF但它没有.命名空间System.ComponentModel.Composition不可用(我甚至尝试过System.Composition但没有运气).也无法使用适用于Windows应用商店应用的Microsoft.Composition NuGet包.

安装NuGet version时的错误是:

‘Microsoft.Composition 1.0.15’ already installed. Could not install
package ‘Microsoft.Composition 1.0.15’.

You are trying to install this
package into a project that targets
‘.NETPortable,Version=v4.5,Profile=Profile7’, but the package does not
contain any assembly references that are compatible with that
framework. For more information, contact the package author.

最佳答案 您需要从包中手动添加对二进制文件的引用.我通常将软件包安装到特定于平台的项目(例如.NET Framework 4.5),然后只需从便携式手动引用.

这将修复NuGet(2.1)的下一版本,我们将更新MEF包以与其一致.

点赞