Hello fedi, any #DotNet and #NuGet experts here please?
I'm trying to prepare a NuGet package where I need to bundle a folder with a DLL and some accompanying files. Everything is good, the nupkg file is created, the folder is there (I can clearly see it with 7-zip). However, when installing the package, the folder is again there in the NuGet global cache, but not in the project where I install it!
I even asked a StackOverflow question [1] about it, but still no dice. Any thoughts please? Thanks!
[1]:stackoverflow.com/questions/78…
I'm trying to prepare a NuGet package where I need to bundle a folder with a DLL and some accompanying files. Everything is good, the nupkg file is created, the folder is there (I can clearly see it with 7-zip). However, when installing the package, the folder is again there in the NuGet global cache, but not in the project where I install it!
I even asked a StackOverflow question [1] about it, but still no dice. Any thoughts please? Thanks!
[1]:stackoverflow.com/questions/78…
External DLLs and other files are in the nupkg and in the global cache, but not installed with the package
I have a .NET 8 library written in C# that uses an external native C DLL, my library is basically a C# wrapper for the C API. I want to make it a NuGet package and use it in my other projects. Here...Stack Overflow
Chet Husk
in reply to André Polykanine • • •Native files in .NET packages
learn.microsoft.comAndré Polykanine
in reply to Chet Husk • • •Chet Husk
in reply to André Polykanine • • •no, you don't need a nuspec. You can do all of this using the Pack and PackagePath metadata like you've done with other package contents.
It's not entirely clear what you mean by 'installed into the project', but you should look inside the project.assets.json in your projects obj folder - this file describes how NuGet sees your package and determines which dependencies will actually end up in your project. If you don't see your native binaries in the project.assets.json...
André Polykanine
in reply to Chet Husk • • •Chet Husk
in reply to André Polykanine • • •André Polykanine
in reply to Chet Husk • • •1. I package my NuGet package using `dotnet pack` and the CsProj you looked at. I'll call this "package".
2. I have another project (I'll call it "app") where I want to *use* the package.
3. I do `dotnet add package` to add the package to the app.
Result? My app does not work because the DLL the package imports is not there at all.
Chet Husk
in reply to André Polykanine • • •Chet Husk
in reply to Chet Husk • • •hello again! I found your project on GitHub and I think I can explain what's happening.
The first image is what your package looks like today, with everything copied into the `lib/net8.0` directory. NuGet only automatically references _managed assemblies_ from folders using the `lib/<TFM>` pattern, which is why only your main `SharpLouis.dll` assembly is here.
To fix this, you need to tell NuGet about your _native dependencies_. This can be done with a line similar to what you have.
Chet Husk
in reply to Chet Husk • • •Here's the line to make NuGet see your native dependency
```xml
<Content Include="./LibLouis/liblouis.dll" Pack="true" PackagePath="runtimes/win-x64/native" />
```
This is very close to what you already had - the key difference here is the PackagePath - NuGet looks for native dependencies at `runtimes/<RID>/native`, so I've placed the native liblouis at `runtimes/win-x64/native`. When you do this, the package changes - the second image shows NuGet seeing the native deps.
André Polykanine
in reply to Chet Husk • • •Chet Husk
in reply to André Polykanine • • •André Polykanine
in reply to Chet Husk • • •Chet Husk
in reply to André Polykanine • • •André Polykanine
in reply to Chet Husk • • •Chet Husk
in reply to André Polykanine • • •André Polykanine
in reply to Chet Husk • • •Chet Husk
in reply to André Polykanine • • •André Polykanine
in reply to Chet Husk • • •André Polykanine
in reply to Chet Husk • • •<Content Include="LibLouis\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
Then I have my DLL where intended, but I started getting random access violation exceptions with message "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Any thoughts on this also, please?
Chet Husk
in reply to André Polykanine • • •Sorry for the delay, I spent part of the day talking to some folks inside the .NET org that manage native dependencies like you do. One example I was pointed to was the SkiaSharp library - .NET bindings to the Skia graphics API. Here is some of their logic for making the local-build dev cycle work: github.com/mono/SkiaSharp/blob…
All of the projects in the repo that use the library Import this file: github.com/search?q=repo%3Amon…
SkiaSharp/binding/IncludeNativeAssets.SkiaSharp.targets at main · mono/SkiaSharp
GitHubAndré Polykanine
in reply to Chet Husk • • •Peter Vágner
in reply to Chet Husk • •Chet Husk likes this.
Marcel T. :
in reply to André Polykanine • • •WCharT.Net/src/WCharT.Net/WCharT.Net.csproj at main · badcel/WCharT.Net
GitHub