0

I'm trying to make Npgsql, the PostgreSQL provider for .NET, available for consumption by Xamarin users. I've explored various methods for doing this and seem to be blocked.

First, a Xamarin project can consume packages which target certain PCL profiles. The problem is that none of of these PCL profiles contain System.Data, which Npgsql requires, even though Xamarin itself allows you to use System.Data.

Second, Npgsql already supports the .NET Platform Standard (version 3), and the documentation on the standard contains the following sentence:

If a library targets .NET Platform Standard version 1.3, it can only run on .NET Framework 4.6 or later, .NET Core, Universal Windows Platform 10 (UWP), and Mono/Xamarin platforms.

However, trying to go down this path yielded several errors (this question is one of them). My guess is that the Xamarin tooling isn't yet fullynetstandard-aware.

Finally, it seems possible to import Npgsql as a shared project inside the user's solution, but this seems like a very hacky and wrong solution - it bypasses NuGet entirely.

Does anyone have any info on this?

Community
  • 1
  • 1
Shay Rojansky
  • 15,357
  • 2
  • 40
  • 69

2 Answers2

0

I believe your speculation is correct of Xamarin tooling not being fully netstandard/PCL5 aware AFAIK(Your speculation is as good as mine). This is a huge effort by all parties involved to be unified. There have also been significant changes on the dotnet end that can alter this.

For your questions about System.Data:

System.Data is missing a bit of functionality: https://developer.xamarin.com/guides/ios/advanced_topics/system.data/#Missing_Functionality

System.Data is available via the Xamarin.iOS.dll assembly as it's not supported in PCLs.

https://developer.xamarin.com/guides/ios/under_the_hood/assemblies/

https://msdn.microsoft.com/en-us/library/system.data(v=vs.110).aspx (Notice no PCL items inside)

Finally, there should be a blog post next week about netstandard via https://blogs.msdn.microsoft.com/dotnet/2016/05/23/changes-to-project-json/

I would highly recommend that you join the .NET core slack channel to ask any questions you may have.

http://tattoocoder.com/aspnet-slack-sign-up/

Jon Douglas
  • 13,006
  • 4
  • 38
  • 51
0

That npgsql package seems to be depending on pre-release packages (RC - Release Candidate). Run the install with -pre option:

Install-Package npgsql -pre

This worked at least when installing to an iOS project. Not sure if it functions correctly as none of the dependencies are added to the References, only Npgsql.

SKall
  • 5,234
  • 1
  • 16
  • 25
  • I did check the "prerelease" checkbox in the VS NuGet GUI, but apparently that doesn't quite mean the same thing... `Install-Package -Pre` worked. However, after Npgsql was installed, trying to actually build the project failed with a `System.IO.FileNotFoundException: Could not load assembly 'System.Security.Cryptography.Algorithms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?` – Shay Rojansky May 27 '16 at 13:05
  • Note: posted a question about the above issue: http://stackoverflow.com/questions/37484894/consuming-netstandard13-packages-from-xamarin-projects – Shay Rojansky May 27 '16 at 13:35
  • It looks like a bug on the package. If you look at the "packages" folder NuGet created you would find these libraries there. The folders for Android & iOS are empty. Why it doesn't fail on iOS could be multiple reasons but I suspect maybe a compiler directive related. Instead of installing it from NuGet your best option would be to work against the source code as the packages are clearly not ready. – SKall May 27 '16 at 13:37
  • I don't think that's a package bug. As I said in the other question (link above), it's valid for lib folders to be empty (_._), meaning that the package is supported but no DLLs are needed; if I understand correctly, in the Mono.Android case the logic is provided by the framework, so no DLL needs to be provided with this nuget. But that doesn't explain the build logic which tries to walk all dependencies. – Shay Rojansky May 27 '16 at 13:56