Sorry readers, running own company possess great challenges, so didn’t do justice to my blog, and when I get free time I use it for sleeping :D.
Recently I had to port our existing Xamarin.Forms Project from PCL to .NET Standard.
It’s not a simple Xamarin Forms project, for upgrading simple projects, we have various blog post covering those. I am taking about Xamarin.Forms project of very large scale (around 100k Lines of Code, more than 500 Views &ViewModels, multiple custom renderes and around 90+ Nuget Libraries).
So all the libraries we used didn’t have support for .NET Standard. So we have multiple requirements here
1. Upgrade our PCL without affecting Git History
2. Keep using Libraries which don’t have .NET Standard support yet.
3. Make sure that your Resx file works as expected. (This I am still experimenting, will be sharing findings).
So the first step you have to make sure is take a copy of your working project in current state and keep it somewhere safe.
If you use git / version control, create a branch and let’s start tinkering with the project. Steps are pretty straight forward.
1. Unload your PCL project (right click -> unload), and start editing it (right -> click edit), VS Mac users, just use Visual Studio code, it’s straight forward.
2. You have to delete everything in the .csproj and insert
<PackageReference Include="" Version=""/>-->
So in .NETStandard approach, there is no packages.config. References included in .csproj So you have to move all the stuff in packages.config to your .csproj.
In my case manually changing the to the new format was time consuming for 90+ Nuget Reference I had, so I wrote a simple C# Console application to make my life easier, sharing it here 😀
3. Delete AssemblyInfo.cs, these informations will be in .csproj and packages.config (also in csproj via PackageReference)
4. Basically Reload the project, you are ready to go. But there is catch if your project contains libraries which don’t have .NetStandard.
So we will need to add FallBack criteria for Nuget restores.
Under Property Group add this line (based on you requirements of which previous PCL profile do you want restores to based on)
Other issues you may face is that if you have any references to Microsoft.Bcl.Build nugets in any of your projects (Platform Specific and the new .NET Standard), remove those references.
To avoid possible issues, it is always better to remove the existing PCL reference from Platform Specific Projects, and adding it again.
Points to take care for avoiding potential crashes.
- If you are were using Embedded Resources in your PCL project, you have to mark the Build actions again. Otherwise those resources wont load.
- If you are using Resx for localization, it’s always best to remove the current file (ofcourse take a backup), add one again with same name and replace contents.
Before Building, clean all bin/obj folders, Rebuild the project with fingers crossed :D.
If you face any issue please don’t hesitate to contact me or I can help you with this, Just mail to muhaymin at fantacode dot com
Do share your experiences.
How to Convert PCL Library to NET Standard and Keep Git History – James Montemagno