Is it possible to create a stand-alone Monotouch class library? - xamarin.ios

I'm all about code reuse. One of the best ways in .NET/Mono is to create a class library. I have a few custom UIViews that I would like to place in a class library (.dll) so that I can redistribute it but for some reason I am not able to create a project that references monotouch from a stand-alone library. The only way to reference it is to create a full blown iPhone project -- not what I want.
Any help would be appreciated.

Under MonoDevelop project types C#->iPhone and iPad, I have
iPhone Window-based Project
iPhone OpenGL Project
iPhone Navigation-based Project
iPhone Utility Project
MonoTouch Library Project
Empty MonoTouch Project
iPad Window-based Project
Universal Window-based Project
You want MonoTouch Library Project. This will compile a DLL that can be referenced in another MonoTouch project.
I know this works because I have 2 projects that reference a DLL I created just for the benefit of reusing code.

Related

Static library file generated from Xamarin Studio

I have a C# project which have all the business logic files. So i need to use those files in ios project. i,e I need to create a framework or library from '.cs' files(C# files).
Is it possible to achieve this by using 'Xamarin'?
I have tried creating the static library project in 'Xamarin Studio'. But i can't find the '.a' lib file generated when i build the project.
Can i create a static library .a file from Xamarin?. If so, then can i use that project in my iOS xcode projects?.
Short answer: no, you can't create a static native library out of a managed project.
But that doesn't mean you can't call your managed call from the native part, but at the end, your project will still be a Xamarin.iOS project.

Sharing projects with MonoTouch

I have a class library project (developed in VS) which I want to share with a MonoTouch project I'm working on. The problem is that when I try to add a reference to the library project in MonoDevelop an error is displayed saying 'Incompatible target framework: v.NETFramework,Version=v3.5)'.
From what I've read on the web I have to create another class library project in MonoDevelop and then link all the project files from the original into it...I'll do this if I have to but i'd rather have a cleaner solution to this, if not a simple project file fix then maybe a script I can run...
Regards
Lee
A Portable Class Library would be the way to go, but unfortunately not yet properly supported in the current version of MonoDevelop with MonoTouch. Work seems to be in progress though.
You do have to create a class library project in MonoDevelop. The library has to be compiled with the MonoTouch version of the framework.
The reason for this is MonoTouch framework is based on the Silverlight lightweight version of the .NET framework.
See here http://docs.xamarin.com/ios/about/assemblies for more info.

Does monotouch support multi-file assemblies through modules?

I'm creating a cross platform set of applications, and some of the assemblies are constructed as multi-file assemblies using a set of modules compiled under visual studio 2010. Does the monotouch compiler support multi-file assemblies like these?
You can create a MonoTouch Library project to do this, however you will have to compile the library for MonoTouch.
To do this properly, here is an example:
On Windows create 2 projects MyApp and MyApp.Code (a class library project)
On iOS create 2 projects MyApp and MyApp.Code (a MonoTouch library project), in a different folder in your source control, of course
Put all the code into MyApp.Code (Windows version), on iOS "Link-In" every file you want to add the to the project from the Windows copy. This keeps one copy of the file, but allows you to compile for multiple platforms
MyApp will just contain UI-specific code on both platforms and is completely different on both platforms
Add #if IPHONE or #if WINDOWS preprocessor directives anywhere you might need them throughout the MyApp.Code project
Rinse and repeat if you want to do the same for Mono for Android, Windows Phone, etc.

How do I change MonoDevelop Target Framework to iPhone for imported .Net library project

I've imported an existing C# library project into a MonoDevelop Solution targeted for iPhone. My original project has a target Framework selection of Mono for iPhone but my newly added project only has Mono/.Net choices. How do I get the iphone targets to show up so I can properly reference it from my existing iPhone targeted projects?
Easiest way I've found is to make a new MonoTouch Library project and either "link" or "copy" the files from the existing project.
This is usually necessary anyway, as usually you will have to add #if MONOTOUCH preprocessor statements in a couple places.

MonoTouch: does it support MEF?

I am trying to port an existing c# .net application that is using MEF extensively to MonoTouch and MonoDroid. Does MonoTouch and MonoDroid support MEF?
Try using PocketMEF.
It is a subset of MEF that can run on PocketPC, WindowsCE, etc.
You will have to create a MonoTouch project from the source, because I would think there would be some minor changes to make it run in MonoTouch.
All the attributes and classes are named the same as standard MEF, you should only have to change a reference and a using statement with #if iPhone to get it working.
According to the list of MonoTouch assemblies and Monodroid assemblies, the MEF assembly (System.ComponentModel.Composition.dll) is not included.
It might still be possible to compile the MEF sources for these platforms, but this would probably require modifications to eliminate unavailable dependencies.

Resources