0

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:

enter image description here

Somehow, I cannot change this folder.

enter image description here

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#?

9
  • The nuget package Tesseract is an alternative for you need or not ? If it is, have you tried to add dependency - stackoverflow.com/questions/7772346/…. If it is not, have you tried to include dll in your nuget package - stackoverflow.com/questions/19478775/… Commented Oct 21 at 7:59
  • I added the Tesseract NuGet Package. I changed the picture in my initial post to show the packages too. Commented Oct 21 at 8:26
  • 2
    Have you read learn.microsoft.com/en-us/nuget/create-packages/…? The link to "probing path" docs will also be very helpful. Commented Oct 21 at 9:54
  • 1
    Ok, thank you. The Link in the third comment helped me a lot. I fixed this problem by using a *.targets file and copy all native dlls in the needed folder. Commented Oct 22 at 14:01
  • 2
    If you were able to solve this problem, please consider posting a self-answer to this question detailing said solution. Commented Oct 22 at 14:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.