问题
I'm attempting to include Castle.Windsor in a Xamarin 3.0 project and a Portable class library that will be used in the project. When I attempt to include this via nuget, I get the following error
PM> install-package castle.Windsor
Attempting to resolve dependency 'Castle.Core (≥ 3.3.0)'.
Installing 'Castle.Core 3.3.0'.
Successfully installed 'Castle.Core 3.3.0'.
Installing 'Castle.Windsor 3.3.0'.
Successfully installed 'Castle.Windsor 3.3.0'.
Adding 'Castle.Core 3.3.0' to FuelCog.Core.CompositionRoot.
Uninstalling 'Castle.Core 3.3.0'.
Successfully uninstalled 'Castle.Core 3.3.0'.
Install failed. Rolling back...
install-package : Could not install package 'Castle.Core 3.3.0'. You are trying to install this package into a project that targets 'portable-net45+sl50+win+wp80+MonoAndroid10+MonoTouch10',
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.
At line:1 char:1
+ install-package castle.Windsor
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
I'm targeting Xamarin.Android, Xamarin.iOS, and Windows Phone 8.0. According to this SO answer, Castle.Windsor works with the Mono framework. I've tried to disable various targets in the PCL properties to see which target was not allowing Castle.Windsor to install properly but it doesn't appear that there is a selection that works.
Does Castle.Windsor not work with PCLs or am I missing something?
回答1:
Windsor is not PCL compatible. There are missing APIs in PCL profile eg. Reflection.
回答2:
MS Unity has PCL support, including support for Xamarin iOS and Droid, although the feature set is obviously somewhat limited in a few ways (mainly around auto registration). In general however it works well.
回答3:
I rolled my own IoC because at the time there really wasn't anything that worked on all platforms without effort, that probably isn't the case now...
Anyway, it is ULTRA simple (probably too simple for some, for my relatively simple scenarios it is great), if you haven't found something else, check it out and free to use...extend where you need.
回答4:
Windsor is not PCL compatible; and will likely not ever be. I suggest trying out ninject, it is PCL compatible and well maintained:
You can get the package from here: https://www.nuget.org/packages/Portable.Ninject/
Also; There is a great article about support IoC Containers and Xamarin here: http://arteksoftware.com/ioc-containers-with-xamarin/
来源:https://stackoverflow.com/questions/24090899/castle-windsor-xamarin-pcl