Reputation: 18789
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?
Upvotes: 5
Views: 2461
Reputation: 20279
Based on the blog post from James Montemagno about How to Convert a Portable Class Library to .NET Standard and Keep Git History:
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.
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.
Upvotes: 4
Reputation: 18789
The steps I took to convert a PCL to a .Net Standard library used some steps from here mixed with my own:
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).
Create a New .Net Standard class library in your project, call it something similar like MyPclProject1
Drag and drop all files from old PCL lib to .Net Stanrdard lib
Open old PCL .csproj file in Notepad and copy and paste all the PackageReference
code into the new .Net Standard csproj file
If you use .resx files you need to add this code to your .Net Standard .Csproj file (not sure why)
then update all the references from the old pcl file to the new .Net Standard file and remove the old library
rename your new .NEt Standard lib to the old pcl name
Upvotes: 2
Reputation: 21
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/
Upvotes: 2