Pete Stensønes
Pete Stensønes

Reputation: 5665

Cant use NuGet to add Unity IoC to a portable class library

I am making a Windows Phone 8 application, however because I would like at some point to also publish this application for Windows 8.1 store I made the effort to factor out the application logic into a portable class library. All good so far.

Now being a good boy I want to use an IoC container, unity by preference (since I am familiar with it in desktop and Win Phone 8 only apps)

So here's my problem; the NuGet Unity package will not install into my portable application with this result:

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.

So is there a unity that works with a PCL? or is this just a shortcoming of the NuGet package?

I failed to find any useful documentation on the P&P website to indicate what platforms it is compatible with, but I know it does support WP8 at the least since the NuGet package is quite happy with libraries targeting just that.

Any guidance from the community would be very welcome here I don't want to abandon using a PCL for my app logic if I can avoid it, but if it comes down to a toss up between that and NuGet for package management I will in order to keep the NuGet goodness.

Could this be related to NuGet and Portable Class Libraries - Package doesn't target any framework? that seems more related to making your own NuGet packages for use in your own PCLs.

Upvotes: 0

Views: 1378

Answers (2)

Matt Ward
Matt Ward

Reputation: 47937

Unity 3.0.1304.1 does not contain any PCL assemblies so you will not be able to install it into a PCL project using NuGet.

The Unity NuGet package contains assemblies that target the following frameworks:

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

You can see these target frameworks if you open the NuGet package into NuGet Package Explorer or download the NuGet package and open it using a program that supports zip files such as 7zip or Windows built-in zip file support.

So your possible options are:

  1. Just use Unity in your main Windows Phone 8 application.
  2. Write your own IOC container.
  3. Use an IOC container that supports PCL projects such as Portable.CommonServiceLocator.
  4. Compile your own PCL version of Unity.
  5. Use a later version of Unity 3.5 since this includes a PCL assembly targeting portable-net45+wp80+win8+MonoAndroid10+MonoTouch10

Updated: 2014-05-11

Unity 3.5 now includes a PCL assembly that targets portable-net45+wp80+win8+MonoAndroid10+MonoTouch10 which will install into a project that targets portable-net45+wp80+win.

Upvotes: 2

Igor Kulman
Igor Kulman

Reputation: 16361

There is no Unity for PCL, but you can use Ninject for example.

Upvotes: 0

Related Questions