Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Mobile / Xamarin

Fire Somebody, Anybody - Or Go Home ...

5.00/5 (3 votes)
3 Apr 2017CPOL4 min read 5.3K  
VS 20017 + Xamarin: can't reference a new Portable Library straight out of the box - another failure of a very basic function

VS 20017 + Xamarin: can't reference a new Portable Library straight out of the box ...

Aside from all the other issues documented elsewhere in their (Xamarin) forum, here's another failure of a very basic function.

I have installed VS 2017 Community on my Windows 10 laptop. I have created a brand new sample Xamarin.Forms portable class application. I've removed the iOS & Windows UWP projects because I don't have a Mac, and I don't want to go through the tedious BS required to make the UWP project work the way that it should straight out of the box. Besides, they're not germane to my issue. Here's the stripped down project structure.

Image 1

This actually builds, and deploys in a relatively quick time to my selected emulator:

Image 2

Thank goodness for small successes. They don't last long, however.

Like any good developer, I want to create a library that I can use in my demo project. Let's say I want a class that contains all the constants I'll be using. I create a new, portable class library.

Image 3

Here's the default class it creates in the new library:

Image 4

Why it started with a page, I don't know, but hey - it does compile successfully. So, let's add a reference to this new library in my main project.

Image 5

Uh, Oh!

Image 6

Ok - let's just make the targets sync up. That'll solve it.

Let's open up the properties dialogs for each project and put them side-by-side:

Image 7

So the main project seems to be targeting Windows Phone Silverlight 8, while the brand new class library is not. But there's a "Change" button there. Since I don't really care much about Silverlight, let's remove it from the target list of the main project.

Image 8

As you can see, it doesn't exist. So how on earth do I get rid of it?

How about adding it to the library project instead?

Image 9

Oh no! Still not there. But look! There's that link to install additional targets. Let's try that.

Unfortunately, this takes you to a page on the internet (https://www.microsoft.com/net/targeting) which is just as useless and nowhere has anything about Silverlight, Windows Phone 8, etc.

It looks like I'm stuck. Maybe I need to update my packages through NuGet, since that was the solution for a problem with the UWP project documented elsewhere.

Here's the package documentation:

Image 10

A total of 9 packages in the entire solution, and 8 of them need to be updated. Let's try that. Let's live dangerously and select them all:

Image 11

That actually worked! Of course, the only reason it worked is because I had gone into the Android SDK Manager (Tools/Android/Android SDK Manager), and added the Android 7 SDK. Doing all those updates only took about an hour.

Also, it added one more package to update (the Android.Build.Download) which I updated, and then had to restart VS 2017.

Rebuild again, and everything still seems to compile. However, I still can't reference my new class library from my main project. My package update, however, provided a clue. Here's what I saw (I've removed lines that are irrelevant):

Attempting to gather dependency information for multiple packages with respect to project 'DemoXamarinFail', targeting '.NETPortable,Version=v4.5,Profile=Profile259'
Attempting to gather dependency information for multiple packages with respect to project 'ClassLibrary1', targeting '.NETPortable,Version=v4.5,Profile=Profile111'

Sigh - For those of you who have remained thus far, there is a terrible, awful, lousy solution for this.

First, right-click and unload the library project:

Image 12

Then, right-click and edit the project:

Image 13

Find the "offending" line:

<targetframeworkprofile>Profile111

And change 111 to 259. Save the file. Exit the file. Right-click and reload the project.

Now, you can add the reference. The solution still builds, and it will run on the emulator.

This is terrible. Someone, as they say, needs to be fired. Here's why.

I'm an MS fanboy. I've been coding for and on Windows since the early 90s. That's a long time, even in human years, let alone dog-years. The ONLY reason I've stuck with this particular problem I'm documenting is because I'm so committed to using Microsoft products.

But let's suppose I'm actually a youngish Project Manager, or middle-ish Engineering Director who wants to get the company into Mobile development. So I order someone to volunteer to explore this technology. Hey, you, wet-behind-the-ears-mobile-noobie. See what Microsoft has and what this Xamarin stuff is all about. He comes back in two days and says, I couldn't get it to work straight out of the box. The app that they create as a default wouldn't compile properly, and wouldn't run on the emulator.

Boom! Next! Microsoft just lost that customer/company forever.

People use Microsoft products because they are easier to use, or have more features, and more importantly, BECAUSE THEY WORK! STRAIGHT OUT OF THE BOX, THEY WORK!

Microsoft will NEVER get new Mobile platform developers if they try and push this crap out to the development community. Fire the product manager, or fire the lead developer, or fire the QA team that let this out the door, or fire the whole lot of them.

But get this stuff straight, or just give up on Mobile.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)