Saturday, September 15, 2012

MvvmCross vNext - portable class libraries - back on track - 4 complete samples building and running...

UPDATE - 19 Dec 2012 - LATEST INFO IS ON http://slodge.blogspot.com/2012/12/cross-platform-winrt-monodroid.html

----------

Three months on from hitting some severe stumbling blocks in the Portable Library support within MonoTouch, I'm pleased to say that the last two weeks have seen huge leaps forwards in the vNext version.

Right now, the Portable Library layer is now running well under all of WP7, MonoDroid and MonoTouch :)

There are still some tooling issues... but overall, this is now working really well - so I'd like to invite users to have a play with the new projects!

Although there is some significant tooling hackery required to get portable library mvvm working, once you've done the initial hackery, then this shouldn't affect your existing workspaces and you should then be able to build and run portable versions of:
  • BestSellers (WP7, Droid, Touch)
  • CustomerManagement (WP7, Droid, Touch)
  • SimpleBinding (Droid, Touch)
  • Tutorial (WP7, Droid, Touch)
... and you might be able to run even more... :)

---

And the benefits for doing this are....

1. Simpler project structures:

2. Automated cross-platform refactoring - e.g. using resharper

3. Simpler porting to new platforms

4. A new plugin structure which makes mvvmcross lighter (smaller executables), which provides developers with more choice and which makes contributing new IoC modules more straightforward - now anyone can provide and consume new "plugins"

---

If you are interested in all this, then here's the instructions:

----

To get the source...

- you will need to download from the vNext branch on https://github.com/slodge/MvvmCross/tree/vnext

- the only working solution in this download is the MvvmCross_All.sln file - which contains all the projects - portable and platform specific.

---

To get your Windows development environment working with this portable branch:

- assuming you start from Visual Studio 2010, Windows Phone SDK 7.5, MonoDroid on a PC

1. Install the Portable Library tools for the VS2010 - http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981

2. Install VisualStudio 2012 on the same PC... this updates the Portable Library tools to include v2 PCL support (which includes some MVVM/DataBinding helpers)


1 and 2. Install the latest PCL plugin from http://visualstudiogallery.msdn.microsoft.com/b0e0b5e9-e138-410b-ad10-00cb3caf4981 - thanks to @dsplaisted for the update.

3. Install VSMonoTouch - https://github.com/follesoe/VSMonoTouch
- be sure to also copy across the v1.0 MonoTouch framework assemblies in the instructions there

4. Follow instructions based on http://jpobst.blogspot.co.uk/2012/04/mono-for-android-portable-libraries-in.html
- these say to install a file called "MonoAndroid,Version=v1.6+.xml" in "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\SupportedFrameworks" with content:



BUT PLEASE NOTE - the target directory is Profile104

5. Install a similar file called "VSMonoTouch,Version=v1.0+.xml" in the same directory and for its content use:


(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!)

After you have done this.... then you should be able to load and run the WP7 and Droid samples within MvvmCross_All.sln 

... and you should also be able to build MonoTouch solutions too. And you should be able to refactor across all 3 platforms!

---

For the Mac:

Assuming you are starting with MonoDevelop with MonoTouch installed on a Mac

1. Follow the instructions in http://stackoverflow.com/questions/12041290/monodevelop-is-it-possible-to-switch-pcls-compiler/12062589#12062589

This is only a temporary hack - it's a workaround for: https://bugzilla.xamarin.com/show_bug.cgi?id=6649

2. Before opening the MvvmCross_All.sln solution, you need to run a search and replace in "*.csproj" files - this search and replace will:
- search for : <targetframeworkprofile>Profile104</targetframeworkprofile>
- replace with : <targetframeworkprofile>Profile1</targetframeworkprofile>

This is only a temporary hack - it's a workaround for: https://bugzilla.xamarin.com/show_bug.cgi?id=7173
3. Sometimes (if I've checked in the wrong .sln file version) then before opening the MvvmCross_All.sln solution, you may need to change the first line from

Microsoft Visual Studio Solution File, Format Version 12.00
to

Microsoft Visual Studio Solution File, Format Version 11.00
This is only a temporary hack - it's a workaround for: https://bugzilla.xamarin.com/show_bug.cgi?id=4919


After you've done these 3 steps.... then you should be able to:
- open the solution
- switch to the Debug|iPhoneSimulator branch
- run the BestSellers, CustomerManagement, SimpleDialogBinding, and Tutorial projects - other projects currently still have unresolved problems.

---

Further Notes....

- I'll be trying to get this branch fully working in the next month (that's my aim!)
- My intention is to switch all future MvvmCross development across to this portable approach 
- If this happens, then I expect the existing non-portable tree will only get bug fixes - not new features.
- The exact timing of any switchover may depend a bit on tool changes from both Microsoft and Xamarin (and it may depend on clashes in my work and leisure time too!)
- There are a number of class and namespace breaking changes in the vNext (portable libraries) branch - most notably:
-- all Cirrious.MvvmCross.Android namespaces have moved to Cirrious.MvvmCross.Droid - this is to avoid name clashing issues with the global::Android namespace.
-- FirePropertyChanged has become RaisePropertyChanged - as this seems to be the more normal method name
- There are a number of fixes on the master branch which are not yet on the vnext branch
- There are a number of changes still to make in the vnext branch - e.g. IMvxServiceConsumer might switch to a simpler IMvxServiceConsumer - following a request/suggestion from @dsplaisted
- There are several dead files and directories left in the tree at present - mainly left over after refactoring - these will get tidied away soon.
- I've not yet tried much WinRT, console or PSS development on the vnext branch - so don't be surprised if those projects don't build or work!
- If anyone wants to help - with code, documentation, tools, samples or suggestions, then you are very welcome - just get in touch.
- As ever, bugs to GitHub issues please, and questions to StackOverflow :)

17 comments:

  1. This is great news Stuart! Many thanks for taking the time to get this working and documenting it... now I just need the time to reproduce it! :)

    ReplyDelete
  2. This is great! Note that the latest version of the Portable Library Tools for VS2010 has the same updates to PCL support as VS2012, so you don't actually need to install VS2012.

    Of course, hopefully this will all soon work together in VS2012 as well :)

    ReplyDelete
  3. How can I get the libraries?

    ReplyDelete
  4. The vnext branch is on github - go to github and choose branch vnext - kind of top left

    ReplyDelete
  5. I'm trying to run the BestSellers sample for Droid but I'm getting this error:

    The "ResolveAssemblies" task's outputs could not be retrieved from the "ResolvedAssemblies" parameter. Parameter "includeEscaped" cannot have zero length. BestSellers.Droid

    WP7 sample works as expected.

    ReplyDelete
  6. Can you ask that as a question on StackOverflow with MonoDroid, MvvmCross, Portable-Class-Library and MSBuild tags... I don't know what it is, but hopefully if it's on SO then one of the PCL and MD experts can help...

    ReplyDelete
  7. Also please include as a full an output panel trace as you can, and what versions you're running of Visual Studio, MonoDroid, etc - we'll find out what this is...

    ReplyDelete
  8. Done a search - not found anything matching this problem description :/ If you look in the BestSellers.Droid references (in solution explorer) then do you see any errors/warnings for the included libraries?)

    ReplyDelete
  9. The Profile1 thing on MonoDevelop just doesn't feel right, anyways, here is the quick one-liner I use to replace on OSX

    find . -name "*.csproj" -exec sed -i.bak s/Profile104/Profile1/g {} \;

    ReplyDelete
  10. Important update on http://slodge.blogspot.co.uk/2012/10/a-temporary-solution-for-profile1-only.html

    ReplyDelete
  11. Great work!
    BTW: XML-Attributes are case-sensitive, so the content of VSMonoTouch,Version=v1.0+.xml should be:




    Regards,
    Sascha

    ReplyDelete
  12. Thanks Sacha... but unfortunately Blogger won't tell me what your code fix was!

    ReplyDelete
  13. Hello,
    I followed the "For the Mac" steps and attempted to run the Cirrious.Sphero.WorkBench.sln for the Ball Control app in MonoDevelop. In attempting to run the code but got "Test execution cancelled." (tried running Debug | iPhone Simulator) I am new to MonoDevelop so my guess is I am not setting the build configurations correctly.
    Please let me know! Thanks
    -Sal

    ReplyDelete
    Replies
    1. This post is out of date - a more recent one was published just before Xmas 2012 - and since then Xam2 has arrived - and more changes are expected from Xam in the next month - your best bet is to to contribute to the discussion on http://forums.xamarin.com/discussion/1549/pcls-and-mvvmcross-in-the-new-tools

      Delete
  14. Actually, there is still some misunderstanding or something with "Profile2"/"Profile104" folders. Not sure if that depends on both VisulaStudio 2010 and 2012 installed, however, I was receiving "There is no available functionality that is portable between the frameworks you have selected" error when tried "Profile104", but that was ok with "Profile2".
    -----
    (I already use Xam).

    ReplyDelete
    Replies
    1. Thanks - these instructions here are quite old now - best to look at the N+1 video setup - and also best to stay clear of Profile2 - if you are playing with that then it won't help you (but I won't explain that here - over to stackoverflow!)

      Delete
  15. But still, it did not allow to add the package via Nuget, so seems for me that's a problem with package info.
    Anyway, I've just built MvvmCross binaries and attached dlls to VisualStudio (2012) as it's shown on this video: https://www.youtube.com/watch?v=UC2r4mmj3UI&list=PLR6WI6W1JdeYSXLbm58jwAKYT7RQR31-W
    Portable library project compliled now.

    ReplyDelete