Parse for Xamarin Forms - No PCL, my solution with conditional builds

About Parse

In my previous article (or next, we will see ;) I talk about Parse BaaS. This is a 'Back end As Services' that offers you simple but really convenient back end capabilities for storage but also managing users... I approach why I choose this technology for my mobile application, looking for advantages and drawbacks.
Parse, after being purchased by Facebook, was closed last year, but fortunately, the source code is open source and Parse still exists. So you can install your own server or use the new Parse on Buddy platform for instance. You can take a look here: https://buddy.com/parse/



The problem with Parse for Xamarin Forms

So, actually the problem is that we can find .NET Xamarin SDK but specifically for iOS and Android frameworks. There is no SDK for Xamarin Forms.

The ideal solution could be the following:



Many 'pseudo' solutions can be found on internet but I will give you mine, using conditional builds in Visual Studio.
I have to mention that some solutions found on internet will work on Visual Studio for PC but not with the new edition of Visual Studio for MAC... So don't be surprised


My 'pseudo' solution, conditional builds

Its an easy solution and just need few configuration steps described bellow. I just use build configurations and conditional building based on these configurations.

1- Download latest Parse's assemblies

The first is to download the latest official Parse's assemblies for android and iOS (in my case 1.7.0.0). I don't use Nuget packages for several reasons. The first is that there is multiple Nuget packages and we don't really know which one to choose (I tried and some don't work with Xamarin)...

Multiple Parse's nuget packages
You can download correct DLLs from here:
https://github.com/parse-community/Parse-SDK-dotNET/releases/tag/1.7.0


2- Copy Parse DLL alongside the nuget packages

Next, I placed these DLLs in a specific folder in my solution to embed it into my source control. I don't want them managed as Nuget packages because it's not.



3- Make new build configurations

Under my solution in Visual Studio I then next generate new build configurations based on the existing ones, as on the schema bellow. In my case I created a new build configuration designed specifically for iOS platform.


These new configurations are just copies of existing ones. Then in Visual Studio:


For more information on how to create new build definitions, please refer to the documentation:
https://msdn.microsoft.com/en-us/library/kkz9kefa.aspx


4- Conditional build depending on current build configuration

Why to create copy of a build configuration ?
In fact we will select the 'correct' Parse DLL depending on the current build configuration (depending on the platform we want to generate the application).

If 'Debug' --> Get Parse.Android to build the solution
if 'Debug iOS' --> Get Parse.iOS to build the solution

This is done by manually modifying the *.csproj (the project) that use Parse. In our example, we would modify 'BusinessLayer.csproj'. We have to add the conditional reference to the correct Parse DLL:

  <Choose>
    <When Condition="'$(Configuration)' != 'DebugiOS'">
      <ItemGroup>
        <Reference Include="Parse.Android, Version=1.7.0.0, Culture=neutral, processorArchitecture=MSIL">
          <HintPath>..\..\packagesExt\Parse.Android\Parse.Android.dll</HintPath>
        </Reference>
      </ItemGroup>
    </When>
    <When Condition="'$(Configuration)' == 'DebugiOS'">
      <ItemGroup>
        <Reference Include="Parse.iOS, Version=1.7.0.0, Culture=neutral, processorArchitecture=MSIL">
          <HintPath>..\..\packagesExt\Parse.iOS\Parse.iOS.dll</HintPath>
        </Reference>
      </ItemGroup>
    </When>
  </Choose>

*.csproj file should look something like that:

5- Select build configuration to build expected platform's app

Now, you just have to select the correct build configuration to build your app. It will automatically include the Parse DLL corresponding to the platform for which you are building the app.

Warning In visual Studio for MAC, in the solution explorer, the reference is not refreshed automatically. But the build process choose the right assembly.

Bellow, building for iOS reference only Parse for iOS assembly:

And voila !
If you have any question don't hesitate.

0 commentaires:

[Xamarin Forms] XAML previewer in Visual Studio 2017 (really slow)

Preview my Xamarin Forms XAML ?

Today, I started a new Xamarin Forms application and for that I decided to use Visual Studio 2017 Community edition.
Why ? Because I know that this version includes interesting features to me. One of this feature is that we can preview our Xamarin Forms XAML pages (theorically in a better way than in VS2015).

First, we have to notice that to preview XF XAML pages, we don't use the exact same way as with  traditional XAML pages. In fact what we are looking for is not the designer but the Xamarin Forms Previewer Window. Take a look at the next steps to understand the differences... 

There is not a lot of details on Xamarin Web site:
https://developer.xamarin.com/guides/xamarin-forms/xaml/xaml-previewer/



XAML Designer vs Xamarin Forms Previewer

On a XF XAML page, right click on the code:
Using traditional "Designer menu" as for traditional XAML page

We got an error

Then use the previewer (menu VIEW\Other Windows\Xamarin.Forms.Previewer) !


Then after 'some times', the previewer Window appears:




XF Previewer, is it cool and smooth ?

Unfortunately for me, I cannot modify my code while the previewer is opened. It is extremely slow to update changes...

So I know that the previewer is still in "Preview", but as is, I can't use it. I have to type my code then If I really need, open the previewer Window.

Bellow, here are the messages from Visual Studio showing me performances issue:






So I will investigate, and maybe wait for the next releases. If you encountered the same issue, don't hesitate to share your ideas ;)


2 commentaires: