dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.12k stars 222 forks source link

Add support for .NETStandard #263

Closed Nimgoble closed 7 years ago

Nimgoble commented 8 years ago

Please add support for .NETStandard. I'm trying to use PCLCrypto with a .NETStandard library and it isn't working because PInvoke.NCrypt isn't compatible with any .NETStandard version.

AArnott commented 8 years ago

While waiting for this, @Nimgoble, you can use PInvoke as-is by adding an imports property to your project.json file that targets netstandard1.1 or later:

{
  "frameworks": {
    "netstandard1.1": {
      "imports": [
        ".NETPortable,Version=v4.5,Profile=Profile111"
      ]
    }
  }
}
AArnott commented 8 years ago

I'm looking into this now.

AArnott commented 8 years ago

As something of a prereq for this work, we need CodeGeneration.Roslyn to support netstandard. I'm working through that.

tofutim commented 7 years ago

Would adding netstandard support end up supporting xamarinmac?

AArnott commented 7 years ago

I guess that depends on which libraries you want to P/Invoke into. But IIRC all of the libraries in this repo have p/invokes into DLLs that only ship with Windows. So what exactly are you hoping to work on xamarinmac? There are the structs that we define, but those have very limited usefulness outside Windows. For PCLCrypto, these structs are useful because some of them define crypto key data structures which apply everywhere.

tofutim commented 7 years ago

pclcrypto and pclstorage

I feel like I used this before successfully when Xamarin.Mac was just Net35. Now that it is its own project type I think it is failing.

tofutim commented 7 years ago

am I incorrect that pclcrypto and pclstorage work in iOS? Shouldn't they work with Unified libraries then? Thanks for your prompt response.

AArnott commented 7 years ago

PCLCrypto does work on iOS. I don't recall whether PCLStorage does.

You can make netstandard projects accept PInvoke by setting the imports property in the meantime.

tofutim commented 7 years ago

I understand that, but now I need a Xamarin.Mac-specific library to be able to use PCLCrypto/PCLStorage and it has no json to modify. PCLCrypto does try to install, so it might be a profile issue where Xamarin.Mac does not support profile 158. I'll experiment.

Update. When I create a Portable Project in Xamarin Studio it is Profile 111 - which is basically netstandard11.

Update2. I am able to install PCLStorage into a new Xamarin.Mac App, but PCLCrypto fails.

Update3. I suspect if the pinvoke.NCrypt target was portable-net45+win+wpa81+uwp10+dnxcore50+MonoAndroid10+xamarinios10+MonoTouch10 it might work.

tofutim commented 7 years ago

PCLCrypto starts to install, but fails at NCrypt. PCLStorage installs without complaints. Could it be that we just need to add another profile to pinvoke.NCrypt in the nuspec?

PCLCrypto

portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10

PCLStorage

portable-net45+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac portable-net45+sl5+wp8+wpa81+win8+monoandroid+monotouch+Xamarin.iOS+Xamarin.Mac

PInvoke.NCrypt

portable-net45+win+wpa81+MonoAndroid10+xamarinios10+MonoTouch10

AArnott commented 7 years ago

We can keep this issue active for netstandard support, but let's keep the PCLCrypto discussion on the PCLCrypto project.

AArnott commented 7 years ago

314 will help us deliver on this easily.