Cross Platform - James Montemagno https://staging.montemagno.com/tag/cross-platform/ https://staging.montemagno.com/content/images/2017/08/MonogramIcon_Orange_NoBuffer.png Cross Platform - James Montemagno https://staging.montemagno.com/tag/cross-platform/ Hugo -- gohugo.io Tue, 13 Oct 2026 23:21:57 GMT 60 Cross Platform Settings for Everyone! https://staging.montemagno.com/cross-platform-settings-for-everyone/ 598df8f2c121b60019bf3039 Wed, 12 Mar 2014 20:40:55 GMT If you haven’t figure it out by now, I simply love portable class libraries. I have been blogging about them, talking about them on Channel 9, and I even did a 18 city roadshow discussing PCLs and Azure Mobile Services.

On my GitHub I have started to build out a lot of applications, sometimes using MvvmCross and sometimes not. One of my most starred repos is my MvvmCross plugin for saving settings on Android, iOS, WP, and Win 8. My idea originally was simple: Use the native settings management system across all platforms. This means SharedPreferences, NSUserDefaults, IsolatedStorageSettings, and ApplicationDataContainer. I didn’t want to do anything too crazy to re-invent the wheel, so this means you can only store data values that the platform allows such as:

  • Boolean
  • Int64
  • String
  • Single
  • DateTime

Doing anything more then this to me means you should use some sort of blob storage such as Akavache. Since my library is very simple this means you can still use a PreferenceActivity on Android to get a nice native settings screen (this was my main motivation really). So it is great that I have MvvmCross support, but what about standard Xamarin projects?

Today, I am pleased to introduce a brand new GitHub repo called “Xam.PCL.Plugins”. This is a repo that is open source and will house all of my PCL NuGet Plugins for cross platform development. To start things off I am introducin my very first plugin, which as you might have guessed is cross platform settings! It is already available on NuGet for your app consumption :)

All you need to do is install the NuGet into both your PCL and client projects and you will be on your way! If you are interested in creating more plugins with me or converting MvvmCross plugins over simply fork my repo and send a pull request. You can use my settings project as an example of how to structure your project to work properly with PCLs. Additionally, PCLStorage is a great repo to also look at for starting development for a more advanced PCL.

]]>
Portable Class Library Tips and Tricks https://staging.montemagno.com/portable-class-library-tips-and-tricks/ 598df8f2c121b60019bf303b Mon, 24 Feb 2014 17:38:00 GMT There has been a recent explosion of PCL use since Microsoft and Xamarin added official support for Xamarin.Android and Xamarin.iOS. It is really amazing to have one project that is shared completely across Android, iOS, and all of the Windows platforms. I have blogged before about how to get “fake” PCL support, but I wanted to give an updated post on how to get up and running with a bunch of tips as well.

It is important to remember that there is nothing special you need to do to get PCL support. If you copied over dlls or added xml files you should remove all of this and just use the Stable branches of Xamarin to get official support.

What is a PCL and what are profiles?

A PCL is a portable class library which is a project template inside of VS and XS which allows you to select platform targets that the project will be compatible with. This is amazing because you have one project that works everywhere. PCLs have actually been around since VS 2010, but they have always been locked into Windows specific platforms, but that all changed last November when Microsoft and Xamarin announced a major partnership which included PCL support for Xamarin.Android and Xamarin.iOS apps. PCLs use these things called “profiles”, which are actually supposed to be hidden from developers, but you will see them everywhere. Profile numbers are a peek into what platforms the PCL supports and how NuGet handles PCL support when installing. There are several parts to a profile such as net45, wp8, and now monotouch and monoandroid. PCLs work a bit interestingly which is that the DLss that are in the .NET subset are actually more like stub methods or interfaces that you are developing against. The DLL that gets used is the DLL that is included in the base project. This still puzzles me a bit and I am not a Microsoft PCL compiler expert like Daniel Plaisted, so you can ask him tons of questions on Twitter.

Tips & Tricks

  1. Remember that PCLs are platform independent. Not all APIs will be available to you.

  2. Don’t try to put platform specific code in a PCL, that is now what they are for. Abstract all platform specific code with interface that you implement on each platform

  3. PCL’s are great for large or small libraries, try to break your project up into small re-usable components. For instance I have a Settings PCL that is cross platform compatible that I reuse on every project. Growing a large PCL is fine, but try to think about how you can reuse code on more projects

  4. Choose only the targets you want to support. The more you select the smaller the subset of .NET you will get. If you select Windows Phone which doesn’t have HTTPClient you will not get access to it.

  5. Use NuGet to fill in the gaps. If you need to use a specific PCL profile be sure to search NuGet to see if there is something to fill in the missing functionality such as HTTPClient or PCL Storage.

  6. Recommendation is to leave out Silverlight and Windows Phone if you are not currently developing for these platforms as they will limite your APIs.

  7. This means use Profile 7 or Profile 78 for your projects based on your needs.

Setup

Here is a short guide on how to create your first PCL:

Visual Studio

Inside of Visual Studio it is easy to create a PCL by simply selecting File->New Project -> C# -> Portable Class Library.

When you select this you will see a dialog pop up asking you what platforms you wish to support.

That’s it you are good to go. As you can see they hide the “Profile” from you, but if you expand your References folder and select the .NET Subset DLL you will see in the path a specific profile that you are using.

Xamarin Studio

Similar to Visual Studio you will create a new PCL by selecting File->New Project -> C# -> Portable Library:

Now instead of popping up the target dialog like Visual Studio does you need to actually edit the project properties to specify the correct PCL Profile:

PCL/NuGet Issues

All PCLs and NuGets are not created equal and you will need to do some testing that is for sure. One issue that a lot of people might run into is with Json.NET that has an official Xamarin Component and also an official NuGet as well. While the NuGet does have official support for Xamarin.iOS and Xamarin.Android and issue does comes up if you are using profiles that include .NET 4.5, which is that Json.NET will install a newer version that is including System.Runtime.Dynamic, which is not supported in Xamarin.iOS. This means that that NuGet in general just will not work. There are a few work around for this and I recommend simply installing the Json.NET component in both the Android and iOS project and then manually referencing this DLL (iOS or Android it doesn’t matter) in your PCL. The only thing you will really miss is the DeserializeAsync, which you can create your self easily by wrapping it in a Task. This may change in the future as I have been working with James to get this fixed, but this can be the case with any NuGet out there so be careful.

I hope this helps you get up and running with PCLs. I love PCLs because they are awesome so always feel free to reach out to me on Twitter with questions.

]]>
Setting up your Cross Platform VM Environment (WP, Win8, Xamarin) https://staging.montemagno.com/setting-up-your-cross-platform-vm-environment-wp/ 598df8f2c121b60019bf3042 Wed, 04 Dec 2013 19:09:00 GMT I am not going to lie, I have always been a Windows guy. There is just something about OSX and iOS that really bothered me. It as more of a feeling than specifics, but this means that I have always ran Windows on a PC. I never had to worry about VMs or complex cases. To be honest everything was perfect, I had VS 2013, Genymotion (android emulator), Windows Phone, Windows 8, and then for iOS I just used Xamarin.iOS and it’s VS integration to debug to a Mac nearby. I didn’t really have to interface with it at all. However, that has all changed as now my main device is this beautiful Mac Book Pro Retina with super specs (16 GB RAM, 512GB SSD, latest i7) and I love it. Well I love the hardware, still trying to get used to OSX. Anyways, I demo a lot and I still love developing inside of VS. Luckily, I can do all of this on the same machine using VMs, either VMWare or Parallels. Each have their own perks, price, and features, but they both seem to be great products for $60. However I did run into some hard times setting up my VM environment to get these following goals met:

  1. Windows 8.1

  2. Windows Phone SDK + Emulator (hyperv)

  3. Xamarin.iOS & Xamarin.Android

  4. Genymotion for Android emulator(virtual box)

The biggest issue here is that running VS + Xamarin is completely fine and easy to setup, however setting up awesome emulators is not. The main reason is that it requires nested virtualization. Each product has their own ways of dealing with it, but they aren’t easy to get setup.

Parallels:

To be honest this was pretty easy to get setup for the WP emulator. They have an easy to follow KB article to follow. Ensure that you make the VM have 2 processors and then you must manually setup each WP emulator to only have 1!! This is important as it can lead to crashes if you don’t (and I saw many crashes of the VM). The setup of Parallels with Windows was really simple, the only thing that bothers me is it tries to integrate to deeply with the host OSX with shared folders and apps. You can turn it all off, but you can just tell that there is too much going on.

VMWare:

After contacting VMWare via Twitter they sent me their KB article on how to set up hyper-v inside the VM. No matter what I did I could never get the WP SDK to install the WP emulators. I have always liked VMWare and the latest version is really nice. I like the setup process, settings screens and how it handles the integration with the host OSX. It feels more a self contained application running which I appreciate.

What about Genymotion?

In each VM platform to enable Genymotion it would require you to disable HyperV, reboot, and then run it. This would kill you WP emulator and is a pain to manage when trying to debug. Another option is to run Genymotion on your Mac and then Tunnel the connection from PC to mac, or in my case I find it easy to just share the code folder on the VM with my Mac, open it in Xamarin Studio and debug and run on the Mac. So this happens to work just fine with VMWare, however Parallels has a bug that VirtualBox can not run side by side with it. It will kill Parallels. So if you have a fast MAC the x86 android emulator is your next best step as it isn’t horrible.

Verdict:

I get the question of what is better between VMWare and Parallels and what should be used. If you need to do Windows Phone development then I recommend Parallels. I happen to actually like how VMWare looks and feels though so hopefully they will catch up. They aren’t that expensive so having them both installed isn’t so bad.

]]>