Tags

, , ,

Getting started with a Cross platform Solution leveraging netstandard1.6

The ideal solution would be composed of an ASP.NET Core and a Xamarin Forms comprised of an android and iOS projects; but for my UWP project I rather not use Xamarin.  All these projects would share a common netstandard class library.

step 1) create cross-platform PCL library and retarget it to netstandard.
open the project.json file under “frameworks”, change “netstandard1.6” to “netstandard1.5”. don’t worry we are still targeting
1.6. just to prove it. right click your project and check your target version.

build our shared netstandard class lib making sure we have 0 errors.

step 2) Add a new Cross-Platform-> Blank Xaml App(Xamarin.Forms Portable) name it anything “DjonTraore”.  VS generate more project than I want.  delete anything ending with an “8” (all win related project) at the end like phone etc…  I rather used native project template for win related projects.

Build the solution. well, I do not have a mac, so the iOS project can not be build;  will have to unload that one. there aren’t any build error but 2 warnings.  the android project warns of conflicts between different versions of the same dependent assembly.  will ignore this one for now.

step 3) add reference to my netstandard1.6 class lib from my Xamarin.Form portable lib. not possible! I have to retarget that one also.  Visual studio won’t let me. its complaining that the project must opt-in to nugget 3.0 etc… Searched Google, recommended approach is to remove Xamarin.Form before retargeting and then reinstalling it afterward.  When reinstalling Xamarin.Form, make sure to get latest stable version.  Had to manually add the Xamarin.Forms
dependency to the Xamarin.Forms PCL project.json file:

in the imports, add: portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10

Rebuilt the solution for nugget to fetch the packages.

–Remove “Xamarin.Forms” from your PCL netstandard dependencies list or the step below raise an exception stating that the following assemblies
are automatically referenced by the build runtime/environment.

manually add references to “Xamarin.Forms.Core.dll” “Xamarin.Forms.Platform.dll” “Xamarin.Forms.Xaml.dll”
\packages\Xamarin.Forms.2.2.0.5-pre2\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10
under your solution packages repository

–add “Xamarin.Forms” again to your PCL netstandard dependencies list

Had to do the steps above because on my machine, it took VS some times before automatically recognizing those 3 libraries.  Once VS recognizes them, I can safely remove them and let the “build runtime” do its job Smile
for some reason, inside my Droid project references, the Xamarin.Android references are not being recognized. hmmm, lets remove
all the Android specific references and re-add them starting with Mono.Android.  Interesting.  soon as Mono.Android is removed,
all the remaining Xamarin.Android.xxx references are now recognized.

Step 4)
Add new Core MVC web app project; open cmd prompt from the core MVC web app  folder root and run the following command “dotnet restore”.  From  your ASP.NET core MVC app, add reference to the netStandard PCL.
Launch the MVC app, et c’est fait, parfait; everything works just fine.

Broken step) Next, Add a UWP project, reference the netStandard PCL;
Wait. does not work.  Google points me in the following direction:
http://stackoverflow.com/questions/38315273/cannot-reference-net-core-library-from-uwp/38319469

the link provided suggest upgrading UWP project to latest stable version. as of this writing, it is 5.2.2.  I also update the UWP project.json file to let the UWP framework know that it can import netstandard1.6 libraries and tried multiple ways to add the netstandard1.6 lib as a dependency to no avail. Trying to make use of old fashion way to reference  my netstandard1.6 PCL  library…. still not working. I guest there is not way to import a netStandard1.6 PCL libs.
will check back on this in the near future.

Note: if U read about UWP netstandard support at the official link provided below, it is obvious that UWP does not support new types added to
netstandard after version 1.4. but that is ok for now in hope Microsoft will make UWP support the latest netstandard version in the near future.
https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-platform-standard.md#mapping-the-net-platform-standard-to-platforms

 

github link to project: https://github.com/mustaphakd/CrossPlatFormSetup

Advertisements