Monday, April 30, 2012

Using Portable Library tools for MonoTouch and MonoDroid part 1....

Warning: This is only a part 1 post - I haven't worked out how to do part 2 yet!

To get MonoTouch and MonoDroid building with portable library project references in VS2010:
  1. Install the Portable Library tools -  http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981
  2. Install VSMonoTouch -  https://github.com/follesoe/VSMonoTouch
    - be sure to also copy across the v1.0 framework assemblies in the instructions there
  3. Follow the instructions on  http://jpobst.blogspot.co.uk/2012/04/mono-for-android-portable-libraries-in.html
    - which basically say to install a file called "MonoAndroid,Version=v1.6+.xml" in "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile2\SupportedFrameworks" with content:

    <?xml version="1.0" encoding="utf-8"?><Framework DisplayName="Mono for Android" Identifier="MonoAndroid" MaximumVersion="*" MinimumVersion="1.6" Profile="*"/>
  4. Installl a similar file called "VSMonoTouch,Version=v1.0+.xml" in the same directory and for its content use:

    <?xml version="1.0" encoding="utf-8"?><Framework  DisplayName="VS MonoTouch" Identifier=".NETFramework" MaximumVersion="1.0" MinimumVersion="1.0" Profile="*" />(Note: this file is even hackier than the MonoDroid one - it points the portable tools at Full .Net v1.0 in line with what the VSMonoTouch plugin does!)
  5. That's it!

Although.... if you do want to use System.Net classes within MonoDroid, then you'll also need to add a proxy assembly for it - a MonoDroid class library project producing a DLL called System.Net and containing a single C# file with contents:

using System.Runtime.CompilerServices;
 
/*
 * not available in MonoDroid :/
[assembly: TypeForwardedTo(typeof(System.Net.Sockets.UdpAnySourceMulticastClient))]
[assembly: TypeForwardedTo(typeof(System.Net.Sockets.UdpSingleSourceMulticastClient))]
[assembly: TypeForwardedTo(typeof(System.Net.DnsEndPoint))]
[assembly: TypeForwardedTo(typeof(System.Net.WriteStreamClosedEventHandler))]
[assembly: TypeForwardedTo(typeof(System.Net.WriteStreamClosedEventArgs))]
*/
 
[assemblyTypeForwardedTo(typeof(System.Net.Cookie))]
[assemblyTypeForwardedTo(typeof(System.Net.CookieCollection))]
[assemblyTypeForwardedTo(typeof(System.Net.CookieContainer))]
[assemblyTypeForwardedTo(typeof(System.Net.CookieException))]
[assemblyTypeForwardedTo(typeof(System.Net.Dns))]
[assemblyTypeForwardedTo(typeof(System.Net.EndPoint))]
[assemblyTypeForwardedTo(typeof(System.Net.WebProxy))]
[assemblyTypeForwardedTo(typeof(System.Net.HttpRequestHeader))]
[assemblyTypeForwardedTo(typeof(System.Net.HttpStatusCode))]
[assemblyTypeForwardedTo(typeof(System.Net.HttpVersion))]
[assemblyTypeForwardedTo(typeof(System.Net.DecompressionMethods))]
[assemblyTypeForwardedTo(typeof(System.Net.WebRequest))]
[assemblyTypeForwardedTo(typeof(System.Net.HttpWebRequest))]
[assemblyTypeForwardedTo(typeof(System.Net.WebResponse))]
[assemblyTypeForwardedTo(typeof(System.Net.HttpWebResponse))]
[assemblyTypeForwardedTo(typeof(System.Net.ICertificatePolicy))]
[assemblyTypeForwardedTo(typeof(System.Net.ICredentials))]
[assemblyTypeForwardedTo(typeof(System.Net.HttpContinueDelegate))]
[assemblyTypeForwardedTo(typeof(System.Net.IPAddress))]
[assemblyTypeForwardedTo(typeof(System.Net.IPEndPoint))]
[assemblyTypeForwardedTo(typeof(System.Net.IPHostEntry))]
[assemblyTypeForwardedTo(typeof(System.Net.IWebRequestCreate))]
[assemblyTypeForwardedTo(typeof(System.Net.NetworkCredential))]
[assemblyTypeForwardedTo(typeof(System.Net.ProtocolViolationException))]
[assemblyTypeForwardedTo(typeof(System.Net.ServicePoint))]
[assemblyTypeForwardedTo(typeof(System.Net.ServicePointManager))]
[assemblyTypeForwardedTo(typeof(System.Net.WebHeaderCollection))]
[assemblyTypeForwardedTo(typeof(System.Net.SocketAddress))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SocketException))]
[assemblyTypeForwardedTo(typeof(System.Net.WebClient))]
[assemblyTypeForwardedTo(typeof(System.Net.OpenReadCompletedEventHandler))]
[assemblyTypeForwardedTo(typeof(System.Net.OpenReadCompletedEventArgs))]
[assemblyTypeForwardedTo(typeof(System.Net.OpenWriteCompletedEventHandler))]
[assemblyTypeForwardedTo(typeof(System.Net.OpenWriteCompletedEventArgs))]
[assemblyTypeForwardedTo(typeof(System.Net.DownloadStringCompletedEventHandler))]
[assemblyTypeForwardedTo(typeof(System.Net.DownloadStringCompletedEventArgs))]
[assemblyTypeForwardedTo(typeof(System.Net.UploadStringCompletedEventHandler))]
[assemblyTypeForwardedTo(typeof(System.Net.UploadStringCompletedEventArgs))]
[assemblyTypeForwardedTo(typeof(System.Net.DownloadProgressChangedEventHandler))]
[assemblyTypeForwardedTo(typeof(System.Net.DownloadProgressChangedEventArgs))]
[assemblyTypeForwardedTo(typeof(System.Net.UploadProgressChangedEventHandler))]
[assemblyTypeForwardedTo(typeof(System.Net.UploadProgressChangedEventArgs))]
[assemblyTypeForwardedTo(typeof(System.Net.WebException))]
[assemblyTypeForwardedTo(typeof(System.Net.WebExceptionStatus))]
[assemblyTypeForwardedTo(typeof(System.Net.NetworkInformation.NetworkAddressChangedEventHandler))]
[assemblyTypeForwardedTo(typeof(System.Net.NetworkInformation.NetworkChange))]
[assemblyTypeForwardedTo(typeof(System.Net.NetworkInformation.NetworkInterface))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.AddressFamily))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.LingerOption))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.MulticastOption))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.IPv6MulticastOption))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.Socket))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.ProtocolType))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SelectMode))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SocketAsyncOperation))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SocketAsyncEventArgs))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SocketError))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SocketFlags))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SocketOptionLevel))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SocketOptionName))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SocketShutdown))]
[assemblyTypeForwardedTo(typeof(System.Net.Sockets.SocketType))]


This approach based on a hint in  http://stackoverflow.com/questions/10361457/is-it-possible-to-use-a-portable-class-library-that-references-system-net-in-mon

I will blog more about this stuff... when I get the final part working - which is building these projects in MonoDevelop on the Mac - currently that's #fail :(

2 comments:

  1. Do you have some TypeForwardedTo for System.Xml.Serialization.dll?

    ReplyDelete
  2. For Droid, yes - it's in https://github.com/slodge/MvvmCross/tree/vnext/PortableSupport/System.Xml.Serialization.Droid

    ReplyDelete