Xamarin forms using .Net Standard 2.0

Introduction

All Xamarin developers, please welcome Net standard 2.0. This is the kind of class library we were waiting for all these years. The .Net standard 2.0 specification is now complete and it is included with Net core 2.0, Net framework 4.6.1 and up to latest versions. It can be used using Visual Studio versions 15.3 and up. Net Standard 2.0 obviously supports C# and also F# and Visual Basic.

More APIs

Net Standard 2.0 is for sharing code via various platforms. It is included with all the common APIs that all .Net implementations, it unified all .net frameworks to avoid any fragmentations in the future. There are more than 32000 APIs in .Net Standard 2.0 most of them that are already available in .Net Framework APIs. Microsoft has made it easy to port existing code to .Net Standard 2.0. It is now easy to extend any .Net Standard to .Net core 2.0 or any versions that come in the future.

NuGet Support

Most NuGet packages currently work well with .Net framework, but not all projects are compatible to move to .Net Standard 2.0, therefore a compatibility mode is added to support them.  Even after compatibility mode, only upt0 70% of packages are supported.

Frameworks and Libraries

Below is the table,list all the support frameworks and libraries. Click here for more details

.NET Standard1.01.11.21.31.41.51.62.0
.NET Core1.01.01.01.01.01.01.02.0
.NET Framework4.54.54.5.14.64.6.14.6.1 4.6.24.6.1 vNext4.6.1
Mono4.64.64.64.64.64.64.65.4
Xamarin.iOS10.010.010.010.010.010.010.010.14
Xamarin.Mac3.03.03.03.03.03.03.03.8
Xamarin.Android7.07.07.07.07.07.07.08.0
Universal Windows Platform10.010.010.010.010.010.0.1629910.0.1629910.0.16299
Windows8.08.08.1
Windows Phone8.18.18.1
Windows Phone Silverlight8.0

Sample to convert PCL or Shared to .Net Standard 2.0

  1. Create a default PCL or Shared based Xamarin Forms applications and name it appropriately and wait for the solution to load
  2. Add .Net Standard class library by selecting .Net Standard 2.0Now project should look something like below
  3. Now remove PCL or Shared based project (VERY Important only after moving all the required project files to Netstandard20Test library) and compile
  4. now rename the NetStandard20Test to NetStandardTest (Same as deleted library), make sure to rename DefaultNameSpace and Assembly to NetStandarTest
  5. Now build the project and see if build is successfully.
  6. Your build should fail with errors as shown below, it is because of the deleted project, now we have to reference back the newly created .Net Standard 2.0 to both Android and iOS
  7. Now edit references on each platform project to add the newly created project as shown below once
  8. references are applied correctly, you should get below errors
  9. Now add Xamarin.Forms NuGet package for all projects
  10. Now build the project and you should see any errors
  11. Microsoft has also released a compatibility NuGet package that makes sure’s all the existing packages are compatible to .Net Standard 2.0
  12. Add NuGet package, Mirosoft.NETCore.Portable.Compatibility to .Net Standard 2.0 project.

Hope this blog is useful to you.

Advertisement

Posted

in

by

Tags:

Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: