I have created a NuGet package containing a .NET Core library for Tesseract OCR, which I then added to my C# project via the NuGet Package Manager in Visual Studio.
After building the solution, a NuGet package is generated as expected.
I then reference this NuGet package in a .NET Core console application. However, when running the console app, I get the following error:
DllNotFoundException: Failed to find library "leptonica-1.82.0.dll" for platform x64.
Inspecting the NuGet package with NuGet Package Explorer, I can see that leptonica-1.82.0.dll is located inside runtimes/win-x64/native.
However, when I look at my project's bin directory, the DLL appears under:
<ProjectName>\bin\x64\Debug\net8.0\runtimes\win-x64\native
But the application only runs successfully if I manually copy the DLL to this path:
D:\MyTesseractOCR\MyTesseractOCR_Execute\bin\x64\Debug\net8.0\x64
Manually copying the DLL is not a viable workaround for me, as the package needs to work for an automation software scenario.
I have tried editing the NuGet package in NuGet Package Explorer, but I cannot seem to control the folder level of the output DLL placement.
I think the reason is, cause the dll is placed in x64 root folder in my library project:
Somehow, I cannot change this folder.
How can I ensure that the native DLL is placed in the correct output directory so that the application can find it at runtime when using Visual Studio with C#?

