不能使用NuGet将Unity IoC添加到便携式类库中

时间:2014-01-18 19:51:01

标签: windows-phone-8 unity-container nuget portable-class-library

我正在制作一个Windows Phone 8应用程序,但是因为我想在某些时候也发布这个应用程序用于Windows 8.1存储,我努力将应用程序逻辑分解为一个可移植的类库。到目前为止一切都很好。

现在我是一个好孩子,我想使用IoC容器,优先选择统一(因为我在桌面和Win Phone 8中只熟悉应用程序)

所以这是我的问题; NuGet Unity软件包不会安装到我的便携式应用程序中,结果如下:

Installing 'Unity 3.0.1304.1'.
Successfully installed 'Unity 3.0.1304.1'.
Adding 'Unity 3.0.1304.1' to Logic.
Uninstalling 'Unity 3.0.1304.1'.
Successfully uninstalled 'Unity 3.0.1304.1'.
Install failed. Rolling back...
Could not install package 'Unity 3.0.1304.1'. You are trying to install this package into a
project that targets 'portable-net45+wp80+win', but the package does not contain any assembly
references or content files that are compatible with that framework. For more information, 
contact the package author.

那么有一个与PCL一起使用的统一吗?或者这只是NuGet包的缺点?

我未能在P&P website上找到任何有用的文档来表明它与哪些平台兼容,但我知道它至少支持WP8,因为NuGet包非常满意那些只针对它的库。< / p>

社区的任何指导都非常欢迎我不想放弃使用PCL作为我的app逻辑,如果我可以避免它,但如果它归结为两者之间的折腾为了保持NuGet的优点,我和NuGet进行包管理。

这可能与NuGet and Portable Class Libraries - Package doesn't target any framework有关吗?这似乎与制作您自己的NuGet包以用于您自己的PCL更相关。

2 个答案:

答案 0 :(得分:2)

Unity 3.0.1304.1不包含任何PCL程序集,因此您无法使用NuGet将其安装到PCL项目中。

Unity NuGet包中包含针对以下框架的程序集:

  • .NETFramework 4.5
  • .NETCore 4.5(Windows Store / WinRT)
  • Windows Phone 8

如果您将NuGet包打开到NuGet Package Explorer或下载NuGet包并使用支持zip文件的程序(如7zip或Windows内置zip文件支持)打开它,您可以看到这些目标框架。

所以你可能的选择是:

  1. 只需在主Windows Phone 8应用程序中使用Unity即可。
  2. 编写您自己的IOC容器。
  3. 使用支持PCL项目的IOC容器,例如Portable.CommonServiceLocator
  4. 编译您自己的Unity PCL版本。
  5. 使用更高版本的Unity 3.5,因为这包括针对portable-net45 + wp80 + win8 + MonoAndroid10 + MonoTouch10的PCL程序集
  6. 更新时间:2014-05-11

    Unity 3.5现在包括一个针对portable-net45 + wp80 + win8 + MonoAndroid10 + MonoTouch10的PCL程序集,它将安装到一个针对portable-net45 + wp80 + win的项目中。

答案 1 :(得分:0)

PCL没有Unity,但你可以使用Ninject作为例子。

相关问题