Search code examples
c#portable-class-librarywin-universal-app

How to migrate a Windows Universal App to Portable Library Project?


I have previously developed a Windows Universal App. I would like to migrate all the non-platform specific code to place in a portable class library project for further development.How to achieve this?

In the Windows Universal App there are some backend C# code controlling UI contents and manipulate the data as well. I may not able to seperate the non-platform specific code nicely. Can I still migrate to PCL project in this case?

I searched on the portable class library documentation as the link below: https://msdn.microsoft.com/library/gg597391.aspx

Portable Class Library documentation

The description looks confusing. Does it mean that I just include my previous app package in the PCL project and then everything works?


Solution

  • How to Migrate

    Unless you changed your question title to "how can I move platform independent portion of my code to PCL", I believe no others can easily understand your meaning.

    I assume that you already have a Windows Universal app project in Visual Studio. Then to move code to PCL,

    1. Simply create an empty PCL project (choose a proper profile), and add it as a reference to your original Windows Universal app project.
    2. Cut (not copy) and paste some source files from your app project to this PCL project.
    3. Compile the solution and fix issues.

    If you don't know what is a PCL profile, read MSDN related materials. If you don't know which source files should go to PCL, and which should remain in app project, do experiments or check out other guys' sample project.

    About The Confusion You Got

    I can only say to understand what you highlighted, you should read carefully what is not highlighted in the same sentence, and the subtitle.

    Clearly when you have a PCL project, and a Windows Store/Phone app project that references the PCL, when you generate the deployment package (.appx) in Visual Studio, the final package will include every needed assemblies.

    It obviously isn't what you described.