Sharing projects with MonoTouch - xamarin.ios

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.

Related

VS2015 Properly Targeting .Net Framework 4.6.1 with new Web Application Project or Class Library

I've created a new Web Application Project in VS2015 using the newer aspnet5 templates. However I can't seem to find a straight answer on how to specifically target the .NET 4.6.1 Framework with it. Looking at the pictures below can someone please shed some light on how to use the newer prject structures but target the .NET Framework 4.6.1 with them. According to microsoft this is possible but I can't make heads or tails on specifically how to do this.
The old and new ways are shown below.
The new way below shows use specific runtime...
With the following showing in the references
The old way seemed much more straight forward. Showing a specifically targeted framework.
The same problem exist for Class Library projects where it seems to want to target an SDK vs a particular version of the framework.
I believe you need to set your DNX_IIS_RUNTIME_FRAMEWORK environment variable to "DNX461". I found this question relevant.

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.

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

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.

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.

How can Apple tell if an app was built in MonoTouch?

Monotouch compiles the app into the native code. How can Apple know that the app was built using MonoTouch? Does Monotouch leaves a signature in the application?
Does Monotouch has its own libraries which could be a trace of the origin or it compiles all the code and all its .NET libraries into native code?
The resulting .app package contains the application binary, your resources as well as the required additional libraries, such as:
montouch.dll;
System.dll;
System.Xml.dll and so on.
As such, it would be trivial for them to check if the application was built with monotouch or not - it is as simple as right clicking the package and then select "Show package contents" in Finder.
However, you need not worry about that, as Apple has just relaxed their License Agreement: http://daringfireball.net/2010/09/app_store_guidelines
And even if the assemblies containing metadata were not included in the app bundle (directory), I am quite sure it is relatively trivial to learn how to recognize from the patterns in the actual code in the app executable that it was produced by MonoTouch, if one would want to. So there is not reason for MonoTouch to try to "hide" that fact.

Resources