New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EPIC: Docs on creating packages that are wrappers of native code #2070
Comments
In order to clarify a bit few points before it's too late, here are few scenario to fully differenciates Scenario 1
Scenario 2
Scenario 3
|
Maybe I don't fully understand the scenarios you describe, but it seems to me the following scenario is missing:
|
@wldevries |
As I see it there are two types of managed code. There are the native dlls that are treated as content and are used via PInvoke. On the other hand there are the C++/CLI dlls that need to be referenced at compile time. Depending on the type of native dll you need a completely different strategy of including them in NuGet packages. As of yet I have been able to create packages that support the first type for both package.json and PackageReference, but I have not been able to create working packages for the C++/CLI dlls at all. |
To minimise risk that I forgot again, something similar to this should allow building a c# project to automatically build a c++ project in both 32 and 64. You can then use <ProjectReference Include=”../whatever/whatever.vcxproj” SetPlatform=”Platform=x86” ReferenceOutputAssembly=”false” />
<ProjectReference Include=”../whatever/whatever.vcxproj” SetPlatform=”Platform=x64” ReferenceOutputAssembly=”false” /> |
Trying my luck here... So my solution includes:
Building the solution places all the files successfully under bin/debug/netstandard2.0 It would be really helpful to have a full example of how to accomplish such a task. 🤷♂️ |
In order to get native properly copied during here is an example of what it could/would look like: <ItemGroup>
<None Include="third_part_native.dll" Pack="True" PackagePath="runtimes/win-x64/native" />
<None Include="ThirdPart.ManagedWrapper.dll" Pack="True" PackagePath="runtimes/win-x64/lib/netstandard2.0" />
<None Include="ThirdPart.ManagedWrapper.dll" Pack="True" PackagePath="lib/netstandard2.0" />
</ItemGroup>
But this issue has been created for exactly these questions, |
KUDOS @tebeco you just solved my problem, after quite some time that i'm working on this. Your explanation and example are perfect, thank you for that! 🎉 |
glad it worked out for you ;) i'm 110% sure there lots of thing i'm doing wrong ^^ |
I wonder if this could be more or less related dotnet/core#5703 spotted on https://themesof.net/ |
This is the best (only?) doc we have on the subject at the moment: https://docs.microsoft.com/nuget/create-packages/supporting-multiple-target-frameworks#architecture-specific-folders
A few weeks ago someone internally contacted me about creating packages with managed and native dlls. I tried explaining this to them, which they gave me feedback that it helped them a lot: With PackageReference NuGet selects compile-time and run-time assemblies independently:
With projects using packages.config (and as I discovered this week, Packet, which is common in the F# community):
If you want to support users using both PackageReference and packages.config in their projects, and you want to use the
This doc has a list of pack input properties: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#pack-target-inputs There are two that appear interesting. The other is |
nice 👍 shame on me |
I am in scenario 2, vendor provided native dll and so files and we have built a managed wrapper. I am shipping the native wrapper and dlls in an Interop (wrapper) and Native (native assemblies only) packages. The Native package ships a folder structure that looks like this: The Interop package depends on the Native package. I am trying to write some unit tests for the interop wrapper. If I reference my Interop nuget package ( This produces the same file and folder structure in my test project output directory on build as when I use @tebeco @zivkan do you know of any way to make this scenario work, so the unit test project knows to look in the runtimes/platform/native folder for the current running platform as part of the dll search path when using |
@ssa3512 For compile time solution if you add the following to your
|
Filed #2322 about unexpected architecture-specific file hierarchy flattening. |
It's also a bit unclear how to package non-assembly files needed by native dll:s I have a scenario (like the scenario 3 above) where I have a bunch of native dll:s that needs to load additional data to function. I figured the simplest approach to handle was to package those data-file together with the dll:s, but it turns out some tools expect only assemblies in the So in addition to how to manage native assmblies please also clarify
|
Hey everyone, I gave up on trying to create a sample that can be cloned & packed. I also limited the scope of the document to the easiest scenario, otherwise it requires too much effort to document (plus trying to explain it clearly enough). Anyway, it would be great for as many people as possible, especially anyone who successfully created a package already, to review and provide constructive feedback, so we can improve the docs for this advanced scenario: |
My PR was perged a while ago and is available on the docs site: https://learn.microsoft.com/nuget/create-packages/native-files-in-net-packages |
This issue is tracking customer requests about how to create a package that is a .NET wrapper of native dll/so.
Out of scope: packages to be used by native (c/c++) projects
Improve documentation on use of runtimes folder and RIDs #600
Current approach to packaging x86 and x64 assemblies #1083
Improve documentation - bait and switch pattern, other #1282
nuspec with dll, native and content in output folder #2038
What is win10 TFM and what is the difference with win? #2237
Include a how-to link for creating a Nuget that references native libraries #2287
Including native assemblies is very confusion and underdocumented #3091
Creating a package for native / specialized runtimes Home#3157
Can't install native package with project.json Home#3958
Including an unmanaged DLL in build output Home#3970
csproj: document how to properly pack platform-specific native assemblies Home#6645
Absolutely need example of how to include native libraries Home#6648
Docs on creating a Native TFM package Home#7168
Current approach to packaging x86 and x64 assemblies Home#7374
[Question] - Pack Native dependencies Home#7479
Architecture-specific files folder hierarchy lost (native subfolders) Home#7698
Guide for packaging C# library using P/Invoke to per-architecture and/or per-platform C++ native DLLs Home#8623
How to copy non assembly files to output directory of application Home#8843
nuspec with dll, native and content in output folder Home#8926
Creating package with x86 and x64 managed and native libraries into single package Home#9272
csproj: how to pack at build platform-specific native assemblies Home#9361
Create a x86+x64 .NET 4.6+Native nuget library and it's driving me NUTS Home#9369
[Question] Packaging Platform specific from Vendor dll Home#9502
NuGet package's content files cannot be imported to .NET project but can be imported to .NET Framework project Home#12564
Common practice to create NuGet package for Windows and Linux Home#11110
how to pack a project which use pinvoke? Home#12637
Any CPU is treated as x86 even when it'll really be x64 dotnet/sdk#1545
The text was updated successfully, but these errors were encountered: