Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for .NET Standard 2.0 / .NET Core 2.2.
The trickiest part of this was the handling of the library file name. The file name differs on Windows (
libgpgme-11.dll
) vs on Linux (libgpgme.so.11
). Mono has a feature called "dllmap" which makes this remapping quite easy to perform:However, this same functionality is not available in .NET Core. Work is currently underway to have some sort of native library loader functionality that would support this (see https://github.com/dotnet/corefx/issues/32015), but as of now, it's not available.
This means I had to hack around it. My initial approach was going to be to have two classes (one for Windows, one for Linux) that implement a common interface:
However,
DllImport
methods must be static, and C# doesn't allow static methods on an interface.Because of this, my approach ended up being quite hacky: I have one class with the Linux methods, one class with the Windows methods, and a wrapper class that has properties for each of them (see
NativeMethodsWrapper.cs
).There was another issue: I wanted to avoid copying-and-pasting the P/Invoke code, however .NET doesn't let you have the same file twice in the same assembly, with two different sets of preprocessor values. So, the Windows and Linux classes needed to be in two separate assemblies.
I updated the build to use ILRepack to merge all the assemblies together, so users shouldn't actually notice any of this hackiness. Ideally this will all be cleaned up once https://github.com/dotnet/corefx/issues/32015 is completed.