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.
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.
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 Framework||4.5||4.5||4.5.1||4.6||4.6.1||4.6.1 ||4.6.1 ||4.6.1|
|Universal Windows Platform||10.0||10.0||10.0||10.0||10.0||10.0.16299||10.0.16299||10.0.16299|
|Windows Phone Silverlight||8.0|
Sample to convert PCL or Shared to .Net Standard 2.0
- Create a default PCL or Shared based Xamarin Forms applications and name it appropriately and wait for the solution to load
- Add .Net Standard class library by selecting .Net Standard 2.0Now project should look something like below
- Now remove PCL or Shared based project (VERY Important only after moving all the required project files to Netstandard20Test library) and compile
- now rename the NetStandard20Test to NetStandardTest (Same as deleted library), make sure to rename DefaultNameSpace and Assembly to NetStandarTest
- Now build the project and see if build is successfully.
- 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
- Now edit references on each platform project to add the newly created project as shown below once
- references are applied correctly, you should get below errors
- Now add Xamarin.Forms NuGet package for all projects
- Now build the project and you should see any errors
- Microsoft has also released a compatibility NuGet package that makes sure’s all the existing packages are compatible to .Net Standard 2.0
- Add NuGet package, Mirosoft.NETCore.Portable.Compatibility to .Net Standard 2.0 project.
Hope this blog is useful to you.
Leave a Reply