Use MvvmCross with dot42 - c#

I'm currently trying some techniques for writing Android programs with C#. I found MvvmCross that is really nice for an old WPF programmer. Sadly, the free Xamarin version does not allow the use of MvvmCross, and licences are far too expensive for playing around.
Now i stumbles across dot42, but could not manage to load MvvmCross into a dot42 project via nuget. I get
Could not install package 'MvvmCross.PortableSupport 3.1.1'. You are trying to install this package into a project that targets 'Dot42,Version=v2.3.3', but the package does not contain any assembly references or content files that are compatible with that framework.
so I guess, Dot42 isn't supported by MvvmCross. Is it possible to use MvvmCross with dot42?

You won't currently be able to easily use nuget with dot42 - nuget hasn't yet added any extension for them.
Also, you won't be able to use MonoDroid-targetted assemblies for dot42 - those assemblies are built against Xamarin's runtime - not dot42.
However... if anyone wanted to get MvvmCross working against dot42, then I believe this should be possible - as dot42 supports quiet a good .Net functionality set, including PCLs. To do so would require editing the source code, cloning the MonoDroid projects and then changing the code that targets Xamarin/MonoDroid runtime objects to instead target the dot42 equivalents. I'd personally love to see this done, but haven't had time to work on it myself.

Related

BluetoothLEDevice in Nuget package consumed by WPF application

I'm attempting to build a NuGet package that can be consumed by WPF applications that utilize the Windows libraries that contain BluetoothLEDevice and related classes. Existing applications that need this functionality are WPF applications and I don't quite understand what the limitations are around this. Currently, some things work while others do not.
For instance, I get a System.PlatformNotSupportedException: 'Windows Runtime (WinRT) is not supported on this platform.' error when I use the device watcher to obtain a reference to the device I'm looking to connect to and then call DeviceInformation.CreateFromIdAsync(...).
What should my NuGet package be targeting in terms of framework/standard version?
What do the existing WPF applications have to target to be able to consume this?
I've tried setting the TargetPlatformVersion to 10 for the WPF app. I also see different results depending on whether I reference my class library in the solution from a WPF project vs. loading it in as a NuGet package.
I'm having trouble finding recent documentation on this.

Xamarin - Android - SQLite - Which C++ Library?

A bit of background...
SQLite is an open source C++ library compiled for multiple platforms. There are several commonly used C# wrappers for this library on several different platforms. Some of the common ones are:
https://github.com/praeclarum/sqlite-net.git
https://github.com/mattleibow/Mono.Data.Sqlite.git
https://github.com/oysteinkrog/SQLite.Net-PCL.git
Here is my one which is a stripped back fork from SQLite.Net-PCL.
https://github.com/MelbourneDeveloper/SQLite.Net.Standard.git
There are multiple versioning issues around SQLite on the different platforms, but recently, a big version issue came in to play on the Android platform. You can read about it here:
http://ericsink.com/entries/sqlite_android_n.html
According to Xamarin:
Note: Due to a change by Google, Android N will now only permit linking to NDK-provided native libraries. libsqlite.so is not an NDK-provided native library. Consequently, existing apps using e.g. Mono.Data.Sqlite.dll will crash when running on Android N. This may include other SQLite-using assemblies, not distributed with Xamarin.Android.
Xamarin.Android 7.0, which is part of Cycle 8, updates Mono.Data.Sqlite.dll to include a custom built version of libsqlite.so, named libsqlite3_xamarin.so.
https://developer.xamarin.com/releases/android/xamarin.android_7/xamarin.android_7.0/
So, my questions are: which Android C++ library should we be using for Android? Does the version depend on the version of the Android OS installed? Where do we get the C++ library from?
It sounds as though Google will only allow a customized version of the library. I guess this means that they will only accept signed libraries and the one compiled from Xamarin will be accepted. If this is the case, how do we get this library and package it up in a .NET Standard DLL, or include it in an Android app package?
I ask this question because this issue has been pointed out in my library here:
https://github.com/MelbourneDeveloper/SQLite.Net.Standard/issues/5
I feel like this is connected to the versioning issue. Anything that can shed some light on this would help. In my repo mentioned above, I have created a branches called Issues/5 which uses a different C++ library called libsqlite3_xamarin which seems to be bundled with Mono.Data.Sqlite but I still get the above issue when my phone goes to sleep.

Consuming packages from Xamarin projects

I'm trying to make Npgsql, the PostgreSQL provider for .NET, available for consumption by Xamarin users. I've explored various methods for doing this and seem to be blocked.
First, a Xamarin project can consume packages which target certain PCL profiles. The problem is that none of of these PCL profiles contain System.Data, which Npgsql requires, even though Xamarin itself allows you to use System.Data.
Second, Npgsql already supports the .NET Platform Standard (version 3), and the documentation on the standard contains the following sentence:
If a library targets .NET Platform Standard version 1.3, it can only run on .NET Framework 4.6 or later, .NET Core, Universal Windows Platform 10 (UWP), and Mono/Xamarin platforms.
However, trying to go down this path yielded several errors (this question is one of them). My guess is that the Xamarin tooling isn't yet fullynetstandard-aware.
Finally, it seems possible to import Npgsql as a shared project inside the user's solution, but this seems like a very hacky and wrong solution - it bypasses NuGet entirely.
Does anyone have any info on this?
That npgsql package seems to be depending on pre-release packages (RC - Release Candidate). Run the install with -pre option:
Install-Package npgsql -pre
This worked at least when installing to an iOS project. Not sure if it functions correctly as none of the dependencies are added to the References, only Npgsql.
I believe your speculation is correct of Xamarin tooling not being fully netstandard/PCL5 aware AFAIK(Your speculation is as good as mine). This is a huge effort by all parties involved to be unified. There have also been significant changes on the dotnet end that can alter this.
For your questions about System.Data:
System.Data is missing a bit of functionality: https://developer.xamarin.com/guides/ios/advanced_topics/system.data/#Missing_Functionality
System.Data is available via the Xamarin.iOS.dll assembly as it's not supported in PCLs.
https://developer.xamarin.com/guides/ios/under_the_hood/assemblies/
https://msdn.microsoft.com/en-us/library/system.data(v=vs.110).aspx (Notice no PCL items inside)
Finally, there should be a blog post next week about netstandard via https://blogs.msdn.microsoft.com/dotnet/2016/05/23/changes-to-project-json/
I would highly recommend that you join the .NET core slack channel to ask any questions you may have.
http://tattoocoder.com/aspnet-slack-sign-up/

Is there any way to share code between UWP apps and WPF apps?

To be clear, I follow the MVVM pattern, and I want to structure my project such that I can share my model code between a UWP app and a standard WPF app. The code I want to share has no UI. I don't relish the thought of finding new tools to replace the ones that I've been using for years that take care of certain tasks like logging, connecting to a document oriented database, etc.
I attempted to start writing a UWP wrapper around some code I already have and reference the model project directly. Visual Studio refused to let that happen, showing me an error message that says "Unable to add a reference to project 'ACK.Model'". The same thing happened when I attempted to put the model in a Universal Library and reference it from a WPF app. I'm not trying to share WPF code. Just the model layer that has no reference to UI libraries.
This is a scary proposition, because it means that if I want to do anything substantial I have to choose to either jump 100% to UWP or stay 100% WPF. NewtonSoft.JSON might have a universal distribution (ASP.NET MVC), but what about ElasticSearch.NET, and other tools needed to make important apps?
I found where the "Portable Class Library" project type was hiding. PCLs will allow me to share my code across WPF and Universal apps as that was one of the options. This solves the simple case of the Model part of my code, but I (still) can't use some of the libraries I want. There are still a large number of libraries that I need that do not have PCL available.
About a year later, with the advent of Visual Studio 2017 there is a more complete solution. If you target your libraries to .Net Standard then the library is compatible with both .Net Core apps and the monolithic .Net targeted app. The support for standard .Net libraries and APIs is fairly complete, as is the support for modern C# language features.
The general advice now is this:
Target .Net Standard for all libraries
Target the appropriate platform for your actual application. (UWP or WPF).
NOTE: if your library has to interact with C libraries or applications, you have to take extra care to make sure you load the correct version.
It appears that there is a solution, but it has to be adopted by the whole tool chain you want to use. When Microsoft introduced Windows Store apps in Windows 8, they also introduced a Portable Class Library (PCL). The purpose of the PCL is to share code between different parts of your application.
When you create a PCL in Visual Studio 2015, you can specify the types of APIs you want it to be accessible from:
Universal Apps
Mono
.Net Core 5
.Net 4.6
This of course, limits the APIs available to you but most of the ones you want to use are OK as long as it's not UI related. There are other limitations as well:
Your project can only be edited in Visual Studio 2015 or greater
You don't have access to special directories from the Environment variable (i.e. user Documents directory, etc.)
You can't link to a library designed for only one of your target platforms (i.e. libgit2sharp, etc.)
There's no way to browse the API for this subset--MSDN needs to get on the stick. MSDN has updated much of the API documentation, but it's still difficult to figure out what applies to your PCL
However, you can link any library designed for a single target platform to your PCL. It's not ideal, but it's better than nothing.
The ASP.NET MVC stack has been ported to using PCLs, so you can use NewtonSoft.JSON directly as well as any other of those libraries used by that application. However, there are several libraries that have not been ported.
This arrangement forces you to think about how you want to integrate better. The .Net Core 5 seems to be stable, but support is in it's infancy. The current generation of Universal Apps as of VS 2015 update 1 uses .Net Core 5 directly.
There are several features from Nuget that are not currently supported even though work is under way:
MS Build extensions (major changes to MSBuild and the project.json structure)
Install/uninstall scripts (related to the removal of the concept of install)
Content (related to install/uninstall, but work is in progress on this)
Content transforms (related to lack of install/uninstall)
I wish I had a more complete answer. But this is as far as I got once I discovered the PCL and how it evolved for the current infrastructure.
I'm in the process of creating a game creation toolkit that incorporates version control right off the bat. I want to be able to deploy a game as a Windows 10 app, or as a standard WPF app, but due to the libraries I'm using to integrate version control I need to create the editor as a standard WPF app. I had to be a bit creative in building the shared code and importing the correct libraries.
First, my project hierarchy:
Project.Model (Portable Class Library)
Project.Model.Versioning (standard C# library)
Mvvm.Toolkit (Portable Class Library)
Editor (Standard WPF application)
I want the core PCL to be able to load a project and deserialize the JSON encoded objects. The PCL did have access to System.IO, but surprisingly it is not the same as the one defined in the standard C# library. Here's how I had to fix things:
After adding the package reference to NewtonSoft.JSON, I had to change the target framework in the packages.config file:
<package id="Newtonsoft.Json" version="8.0.2" targetFramework="portable-net452+win81" />
All projects dependent on my Project.Model class had to install the `system.io.filesystem' package from nuget so that the System.IO.FileInfo etc. objects were the same.
While this is definitely not a panacea, it's also not a dead end. I'm sure there are more gotchas, but this will at least help with some of the problems.
a .NET Standard library could be used to share a Model-View-ViewModel architecture between a WPF project and a UWP project.
https://www.syncfusion.com/ebooks/xamarin-forms-succinctly/sharing-code-among-platforms
https://devblogs.microsoft.com/dotnet/announcing-uwp-support-for-net-standard-2-0/

Xamarin shim assemblies and PCL

I want to be able to convert some existing code which uses standard.csproj, droid.csproj and ios.csproj so that they are all based on PCL thus simplifying the solution.
I have read and looked at the shim solution suggested here:
http://slodge.blogspot.co.uk/2012/12/cross-platform-winrt-monodroid.html
But:
1: I am unsure how to actually use the shim assemblies - do I reference these instead of the GAC versions?
2: There is a lot of mention that iOS isn't working yet. Is this the case?
w://
The official support for PCLs from Xamarin is due in Alpha any day now - expect it before the end of June 2013.
Until then, you can see how to use PCLs by including the shim assemblies from MvvmCross - take a look at:
the PortableSupport shims source - https://github.com/slodge/MvvmCross/tree/v3/PortableSupport
the Nuget 2.5 PortableSupport package - https://www.nuget.org/packages/MvvmCross.PortableSupport/
the 25 videos on http://mvvmcross.wordpress.com/ all of which use PCLs
the accompanying source code for those videos - the .csproj files will show you how the shims are used - https://github.com/slodge/NPlus1DaysOfMvvmCross
lots of other PCL based x-plat samples on https://github.com/slodge/MvvmCross-Tutorials/
For additional shims, watch questions like TPL on PCL for MvvmCross for PCL Profile 78 (I know people have got this working - just waiting for them to answer the question...)
When Xamarin official PCL support ships then I anticipate that they will ship official shims and we can retire the MvvmCross ones. However, no-one at Xamarin has given me any answer about this - for latest on this, maybe see status of https://bugzilla.xamarin.com/show_bug.cgi?id=8035

Categories