Xamarin.Forms Tip : Easiest Way to Convert a PCL Project to .Net Standard Project

Xamarin.Forms Tip : Easiest Way to Convert a PCL Project to .Net Standard Project

Microsoft updated the Xamarin.Forms project templates in VS 2017 to use .Net Standard instead of PCL for writing the shared code (including the Xamarin.Forms UI more details here) as NET Standard is the future of cross platform code sharing see this blog for more information on .Net Standard.
But what about our existing applications which we have developed till now using PCL project, well James Montemagno has already this video on channel 9 however the method mentioned there requires to create a new Project and move all your previous code from PCL project to new .Net Standard project.
I have another easier solution .i.e. to just change the .PROJ file XML of the PCL project to that of .Net Standard project, which I will mention in this article in step by step manner. I will use the sample code of my old blog about using SkiaSharp with Xamarin.Forms.

Step-1: Open your existing project and you will see a screen like following mentioning the common code project as Portable.

Step-2 (Optional): Update all the Nuget Packages for the solution to the latest.
Step-3: Delete ‘AssemblyInfo.cs’ present in the Properties folder of the PCL Project as showing in below image.

Step-4: Once done Save & Close the Solution and Visual Studio as now we will be using NotePad (or any other text editor) to update the .PROJ file.
Step-5: Open the .PROJ file present in the PCL code folder in NotePad, the code will look something like following image.

Step-6: Delete all the XML and copy following XML there:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="2.5.0.122203" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Update="NETStandard.Library" Version="2.0.1" />
  </ItemGroup>

</Project>

Step-7: Open the ‘packages.config’ file in another window of NotePad, it will look something like following screenshot:

Step-8: Now update the XML of the .PROJ file (open in previous NotePad window) by adding PackageReference in the ItemGroup tag for each Nuget Package Except Xamarin.Forms (as it’s already there). Also if you are using and 3rd party library please check with the Package documentation about which version of .Net Standard they support before upgrading if they don’t then you can add PCL Compatibility Package later using Visual Studio. The XML of my project file looks like this now

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="SkiaSharp" Version="1.59.3" />
    <PackageReference Include="SkiaSharp.Views.Forms" Version="1.59.3" />
    <PackageReference Include="Xamarin.Forms" Version="2.5.0.122203" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Update="NETStandard.Library" Version="2.0.1" />
  </ItemGroup>

</Project>

Save and Close the file and NotePad.
Step-9: Now open the Solution again in Visual Studio and you will see that Portable is not there like following screenshot.
Step-10: The PCL project is not converted to .Net Standard Library, just build and execute the code and you are good to go. The updated code is available on Github

🙂 🙂 🙂 Happy Coding 🙂 🙂 🙂

3 thoughts on “Xamarin.Forms Tip : Easiest Way to Convert a PCL Project to .Net Standard Project

  1. I see you don’t monetize your blog, don’t waste your traffic, you can earn extra bucks
    every month. You can use the best adsense alternative for
    any type of website (they approve all websites), for more details simply search in gooogle:
    boorfe’s tips monetize your website

Leave a Reply

Your email address will not be published. Required fields are marked *