How do I convert a PCL to a .Net Standard library
Asked Answered
E

3

5

So I have a PCL project but would like to now update it to support .Net Standard

I have read on the Microsoft website steps to do this:

  • Right-click on the project file and select Properties.
  • Under Library, select Target .NET Platform Standard.

But this button does not exist in the latest version of Visual Studio 2017.

I have also read here:

  • Close the solution in VS
  • Take the existing csproj and make a copy of it somewhere else. I’ll keep this other copy open in Notepad.
  • Copy/paste the contents of the new project you created and replace the contents of your existing project. Most of what you had in the old project isn’t really needed anymore. What you’ll likely need are settings like any signing or assembly names that don’t match the folder name/conventions. If you have ResX files with design-time generated code, you’ll need to add the following. Likewise, for Xamarin Forms pages, you’ll need this.

But I don't understand the steps highlighted above as I have loads of nuget packages and ResX files so always causes build errors when I try

So are there any straight forward steps to updating a PCL project to a .NetStandrard one?

Elwin answered 19/10, 2017 at 8:37 Comment(2)
I find it easier to just create a new solution and projects and copy paste all the classes.Heavierthanair
@Heavierthanair what about all the nuget packages? I don't want to have to reinstall all those. Took me long enough uninstalling and reinstalling them all to use PackageReferenceElwin
E
2

The steps I took to convert a PCL to a .Net Standard library used some steps from here mixed with my own:

  1. Convert all nuget packages from the old packages.config way to PackageReference

Unfortunately there’s no current migration tool, so it’s probably easiest to uninstall your existing packages, make sure the packages.config file is gone and then install the package after setting the VS Options to PackageReference. You can also do it by hand (which is what I did for my projects).

  1. Create a New .Net Standard class library in your project, call it something similar like MyPclProject1

  2. Drag and drop all files from old PCL lib to .Net Stanrdard lib

  3. Open old PCL .csproj file in Notepad and copy and paste all the PackageReference code into the new .Net Standard csproj file

  4. If you use .resx files you need to add this code to your .Net Standard .Csproj file (not sure why)

  5. then update all the references from the old pcl file to the new .Net Standard file and remove the old library

  6. rename your new .NEt Standard lib to the old pcl name

Elwin answered 19/10, 2017 at 13:3 Comment(0)
E
4

Based on the blog post from James Montemagno about How to Convert a Portable Class Library to .NET Standard and Keep Git History:

  • Unload your PCL project (right click -> unload), and start editing it (right -> click edit)
  • Delete Everything in the csproj and insert this:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
      </PropertyGroup>
    
      <ItemGroup>
        <!--<PackageReference Include="" Version=""/>-->
      </ItemGroup>
    
    </Project>
    
  • Add back NuGets (simply open packages.config, and add the package references above, or via the NuGet package manager.

  • Delete AssemblyInfo.cs (this is now in the csproj) and packages.config (also in csproj via PackageReference)

Today there are many guides available (e.g. like this one), but they are basically the same (except some project specific peculiarities. And what I read is that you need VS 2017 at least for this.

Engleman answered 4/12, 2019 at 13:0 Comment(1)
simple and staight forward. we can add the package name and version that will be easierEthridge
H
2

In my opinion, the best way it's to create a new project (.net standard) from scratch and copy all stuff to there... Here you have some help: https://blog.xamarin.com/building-xamarin-forms-apps-net-standard/

Hazelton answered 19/10, 2017 at 11:41 Comment(0)
E
2

The steps I took to convert a PCL to a .Net Standard library used some steps from here mixed with my own:

  1. Convert all nuget packages from the old packages.config way to PackageReference

Unfortunately there’s no current migration tool, so it’s probably easiest to uninstall your existing packages, make sure the packages.config file is gone and then install the package after setting the VS Options to PackageReference. You can also do it by hand (which is what I did for my projects).

  1. Create a New .Net Standard class library in your project, call it something similar like MyPclProject1

  2. Drag and drop all files from old PCL lib to .Net Stanrdard lib

  3. Open old PCL .csproj file in Notepad and copy and paste all the PackageReference code into the new .Net Standard csproj file

  4. If you use .resx files you need to add this code to your .Net Standard .Csproj file (not sure why)

  5. then update all the references from the old pcl file to the new .Net Standard file and remove the old library

  6. rename your new .NEt Standard lib to the old pcl name

Elwin answered 19/10, 2017 at 13:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.