Giorgos Betsos Giorgos Betsos - 5 months ago 52
C# Question

Add reference to a library project from an applications PCL project

I have created a library project in

Xamarin.Forms
and I'm trying to consume the functionality implemented by this project from another application PCL project created in Visual Studio.

I first added the library project to the solution of my application PCL project by right clicking on the solution name and selecting
Add -> Existing Project
.

Here's how the solution structure of my solution looks like after adding the existing library project to it:

enter image description here

The library project added is the last one and is highlighted by the red rectangle.

I then tried to add a reference to the library project by right clicking on the
References
section of my application project and selecting
Add Reference ...
. In the dialogue open I selected the library name i.e.
Xamarin.FormsBook.Toolkit
and clicked ok.

enter image description here

After doing that I received the error:


Unable to add a reference to project 'Xamarin.FormsBook.Toolkit'. The
targets of Portable Library project 'Xamarin.FormsBook.Toolkit' are
not the same or compatible with the targets of the current Portable
Library project.


I checked the targets of both the library and the application project and found out that my library project was missing the 'Windows Phone Silverlight 8` target. Unfortunately I'm unable to either remove this target from the application project or add the target to the library project.

Any ideas on how I can get around this issue?

Answer Source

In Visual Studio 2017, Silverlight has been removed as an option.

You can edit the .csproj file of your FormsBook.Toolkit library and look for the Tag <TargetFrameworkProfile>. To disable Silverlight, you should change it to Profile111 (or the same thing your other library has).

You can find a list of these profiles in Stephen Cleary's Blog.