I have both a Xamarin Client and Asp Core Web API that need to reference the same project, which will be used as a Portable Class Library. Sounds simple, but I'll take you through my process. The PCL is just a Model so I can use the same classes for transporting JSON between them).
Process: I create a standard .NET PCL, then attempt to reference it in my Xamarin project. Xamarin is unable to add it since "Portable Library projects can only reference other Portable Library projects". Ok, no worries. I'll create one of those and try it.
I Create a "Class Library (Portable)" dll instead. I configure the project so it matches the same targets (one of them being "ASP.NET Core 1.0") as my Xamarin project, and it imports perfectly. I can use it fine - yay!
Alright, since the "Class Library (Portable)" dll targets ASP.NET Core 1.0, I shouldn't have any issues referencing it in my Web API project. I add it to my project.json...
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
],
"dependencies": {
"TestClassLibraryPortableDll": {
"target": "project"
}
}
}
},
and all is well. BUT, I can't actually refer to the namespace from within my WebAPI project.
This is as far as I have gotten, after trying so many different things. Standard .NET dll's, ASP.NET Core class libraries, .NET Platform Standard conversions... all sorts.
I feel like I'm missing a very simple but very important step. Any ideas?
My WebAPI will be deployed on Linux, if that helps. Does this mean I have to go with the new netstandard? It seems dodgy at best (and has very little documentation).
I've also posted in the ASP.NET Core forums, and was told this:
If you need to target linux, then you need to target netstandard and so can only use netstandard libraries. You need to change your model (MUST be a netstandard library) and add it to the dependencies.
And here's my reply:
Ok, so I create a NetStandard PCL as my Model class. This references perfectly on my WebAPI project, but not on my Xamarin project.
This happens AFTER I convert my Xamarin project to a netstandard library, as detailed in this post.
Does anyone have any suggestions? I may just have to have a set of classes that I can include in each of the projects (or perhaps keep the models in my WebAPI project, and reference it from my Xamarin, if possible) just so I can move on and get some work done.