Forum Cross Platform with Xamarin

Change/upgrade from PCL to .NET Standard

NielsCupNielsCup NLMember ✭✭✭
edited January 2018 in Cross Platform with Xamarin

So I was I upgrading one of my apps from PCL to .NET Standard and ran into some issues. I was about to ask a question here but I eventually managed to solve all issues myself. I will add my findings below anyways in case someone else runs into these same issues:

FYI: I am using Visual Studio for Mac 7.3.2

I have found 2 ways to upgrade to .NET Standard:
1) Adding a new .NET Standard library and copy/pasting everything from my PCL library
2) Upgrading an existing PCL to .NET Standard library

1) Adding a new .NET Standard library and copy/pasting everything from my PCL library (watch this video)
1. Add a new .NET Standard library
2. Copy/paste all files from your PCL to the .NET Standard library
3. Add the Microsoft.Nre.Portable.Compatibility nuget package
4. Add the compatibility flag to the .csproj file
5. Add the required nuget Packages to the .NET Standard library

The above method is (kind of) OK for small projects but for larger projects it is not doable. So there should be a better way:

2) Upgrading an existing PCL to .NET Standard library
If you double click the PCL project and look under Build > General, you can select .NET Standard Platform there. But if I do this I get multiple errors:

  • Xamarin.Forms targets have been imported multiple times. Check your project file and remove the duplicate imports.
    I can solve this by removing this line from the .csproj file, but why is it even in there?:

    <Import Project="..\packages\Xamarin.Forms.2.5.0.122203\build\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.2.5.0.122203\build\portable-win+net45+wp80+win81+wpa81\Xamarin.Forms.targets')" />
    
  • Next, some of my packages aren't restored. If I take a look at the Package Console I see the following output:

    Package Xam.Plugins.Settings 2.5.4 is not compatible with netstandard1.4 (.NETStandard,Version=v1.4). Package Xam.Plugins.Settings 2.5.4 supports:
          - monoandroid10 (MonoAndroid,Version=v1.0)
          - net45 (.NETFramework,Version=v4.5)
          - portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
          - uap10 (UAP,Version=v1.0)
          - win8 (Windows,Version=v8.0)
          - wp8 (WindowsPhone,Version=v8.0)
          - wpa81 (WindowsPhoneApp,Version=v8.1)
          - xamarinios10 (Xamarin.iOS,Version=v1.0)
          - xamarinmac20 (Xamarin.Mac,Version=v2.0)
    

This tells me that the Xam.Plugins.Settings package is not compatible so lets upgrade that. But if I remove the Xam.Plugins.Settings package and try to install the latest version I get the following error:

Detected package downgrade: NETStandard.Library from 1.6.1 to 1.6.0. Reference the package directly from the project to select a different version. HW (>= 1.0.0) -> Xam.Plugins.Settings (>= 3.1.1) -> NETStandard.Library (>= 1.6.1) HW (>= 1.0.0) -> NETStandard.Library (>= 1.6.0) 

I finally fixed this by going into my project.json and set the following:

"NETStandard.Library": "1.6.1"

This was my last error to fix and finally everything worked as it should.

One thing I still don't quite understand is that if I compare the .csproj files of the newly created library and the upgraded library (of the same project) they are completely different. Also the upgraded project now has a project.json and the newly created library doesn't, any thoughts on this?

Best Answer

Answers

  • mattwardmattward GBMember Xamurai
    edited January 2018

    Creating a .NET Standard library project will create an Sdk style project, which is a newer project format. This uses PackageReferences instead of using a project.json file.

    Upgrading the PCL project to .NET Standard from the project options Build - General will add a project.json file. The project file format is not changed to an Sdk style project in this case.

  • NielsCupNielsCup NLMember ✭✭✭
    Thanks for your answer @mattward. So if project.json is deprecated, what is the way to go here, don't upgrade a PCL via Visual Studio (Mac), but create a new library instead? Or is there another upgrade tool to upgrade your project.json project to the Sdk Style project?
  • NielsCupNielsCup NLMember ✭✭✭
    edited January 2018

    Thanks. Accepting yours as the answer, you look like can use some badges :) !

  • FlorianMICHALONFlorianMICHALON FRMember ✭✭✭

    For VS 2017 for windows what is the best solution for upgrade my PCL project to Net Standard ?

  • NielsCupNielsCup NLMember ✭✭✭
    edited March 2018

    @FlorianMICHALON
    The best way is to: Add a new .NET Standard library to your project and copy/pasting everything from your PCL library.
    See this video

  • ZoliZoli NLMember ✭✭✭
    edited March 2018

    PCL project: Why I don't have the upgrade PCL project -> to .NET Standard in the project options ?
    Target .NET Platform Standard is missing, see:

    VS 2017 15.6.4
    Xamarin 4.9.0.752
    Xamarin.Forms 2.5.0.122203

Sign In or Register to comment.