Xamarin.Forms: STL Brews – Anatomy of a Forms PCL project

In this lesson

  • PCL Profiles
  • Adding Nuget Packages
  • Adding/Removing project references
02:20 C# 100

Transcript

Tap on time to skip ahead

00:10

A Portable Class Library, or PCL for short, is one way that we can share code across multiple platforms. Something that differentiates a PCL from something like a shared library is that our code will be compiled into a stand alone DLL.

00:25

If we double click on our PCL project and go into our General build settings, you will see a drop down for different Profiles. A Profile represents the different devices that the PCL can support as well as different versions of the .net framework. As you can see, as I change my framework, I also change the Profile.

00:46

By default, Xamarin creates a Profile 78 PCL for mobile projects. One thing that you might find with other types of profiles is that if you’re doing something for Silverlight 5, or maybe some of the lower frameworks, you might not have access to certain APIs, or you might have access to APIs that are a bit reduced, much like the reflection API.

01:12

One way that PCLs are distributed is through NuGet. If you double click on the Packages folder in your PCL project or in your iOS or Android projects, the NuGet gallery panel will open. From here you can search for particular NuGet packages. I created one called Monkey Arms a few years back. Or you can see a list of the most commonly used PCLs.

01:37

For this project, we’ll need to be able to serialize our models to and from Json. So I’m going to add the Json.net PCL to my PCL project. If you create a PCL, let’s say, after generating the solution and you need to add a reference to it, if you double click on the References folder for that particular project and select the Projects tab, you can turn off and on references to your PCL. In addition, it will only show or highlight PCLs or other projects that are compatible with the current projects settings. As you can see here, I cannot link my Android project to my iOS project.