Adding a PCL to a solution

ScottHalpernScottHalpern USMember ✭✭

Realy simle question here, but I can't figure it out from the docs.

How do you add a PCL to a new solution?

Also, is the PCL the best mehanism to re-use code I anticipate using in many different apps?

Thanks!

Tagged:

Answers

  • EidandEidand GBMember, University ✭✭✭

    a pcl file is nothing more than a class library so yes if you envisage reusing the code then definitely do it that way. For example I have my own NuGet feed and I pull stuff I need from there. It makes development very quick.

    Just one thing to be aware, there are multiple pcl profiles so when you build a pcl make sure you target something that Xamarin understands. You can have xamarin ios and android as targets, just click on properties and the targets will be shown to you.

    You add it to a project by simply adding a reference to that dll just like you add a normal class library.

  • RyanDavisRyanDavis AUInsider, University ✭✭

    In case this was a question about how to create a PCL - it's available in the new project dialog:

    Imgur

    As Eidand says, make sure you check the set of platforms you want to support in the following dialog!

  • ScottHalpernScottHalpern USMember ✭✭

    Thanks for the answers and explanations! However, I am working in Xamarin Studio (Mac), I actually wasn't able to figure out how to link a PCL.

    I created a simple PCL, then started a new solution. I then right clicked references and clicked projects (as described in this tutorial http://developer.xamarin.com/guides/cross-platform/application_fundamentals/pcl/introduction_to_portable_class_libraries/) but I was not able to locate the PCL.

    How do I browse my filesystem to find the PCL? What am I missing?

    I will be sure ot be cognistant of what profiles I target.

    Thanks!

  • RyanDavisRyanDavis AUInsider, University ✭✭

    Hi @ScottHalpern,

    From what you've said it sounds like you created a PCL in one solution, then created a new solution with a different, non-PCL project. The tutorial expects you to have created the PCL in the same solution that your platform projects are in, which is pretty typical for most cross-platform app development. When you have multiple projects in the same solution, you will be able to see the others from the projects page of the references dialog of any project. Unless you have a good reason not to do so, I would suggest you add the PCL project to your new solution (I don't have XS handy right now but it will be something like right click on the top level solution, "Add Existing Project"). Once that's done you should find it available in the references dialog.

    The alternative is that you open and build your PCL project, then reference the compiled .dll from your new project. This is generally a bit of a hassle, can make iterating and debugging harder, etc.. So I would avoid it if at all possible!

  • ShimmyWeitzhandlerShimmyWeitzhandler USMember ✭✭✭

    @RyanDavis
    I'm on VS and I have an existing solution, how do I add a PCL (UWP, Droid, iOS) to the existing solution? When I add a simple PCL, only one projects gets added. What's the right way to do it?

Sign In or Register to comment.