简体   繁体   中英

How do I convert a PCL to a .Net Standard library

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?

在我看来,最好的方法是从头开始创建一个新项目(.net 标准)并将所有内容复制到那里......这里有一些帮助: https : //blog.xamarin.com/building-xamarin-forms -应用程序网络标准/

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

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 (eg likethis 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM