Can’t find .so file in nuget package when deployed via Docker

I’ve written a nuget package that uses some compiled rust code and want to be able to use this package on both linux and windows. I’ve compiled the rust code to a .dll and .so, and included both in the nuget package. Including the nuget package in my .net core project and testing locally on windows works fine. The issue comes when I deploy my .net core project within a docker container, to my linux based web server. Whenever any code in the nuget package that requires the .so gets called, I receive the exception:

Unable to load shared library 'opaque' or one of its dependencies. In order to help diagnose loading problems, consider using a tool like strace. If you're using glibc, consider setting the LD_DEBUG environment variable: 
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.4/opaque.so: cannot open shared object file: No such file or directory
/app/opaque.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.4/libopaque.so: cannot open shared object file: No such file or directory
/app/libopaque.so: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.4/opaque: cannot open shared object file: No such file or directory
/app/opaque: cannot open shared object file: No such file or directory
/usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.4/libopaque: cannot open shared object file: No such file or directory
/app/libopaque: cannot open shared object file: No such file or directory

This error is pretty easy to understand, I’m just not sure how to fix it. I’m pretty sure this issue is due to deploying via docker, as normally, it seems like nuget pacakges installed on linux will be placed in the /share/ directory, hence that’s why its trying to find it there. I assume installing the nuget package from within the docker container is preventing this though.

Does anybody know how to fix this? Either specify a different path or somehow have my nuget package installed to the right directory?

I’m referencing the dll via attribute like so:

[DllImport("opaque")]

The nuget package structure looks like this:

project/
    .dll
    .so
    .csproj

Here is how I’m specifying the .dll and .so in the project file

  <ItemGroup>
    <None Update="libopaque.so">
        <Pack>True</Pack>
        <PackagePath>lib$(TargetFramework)</PackagePath>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="opaque.dll">
      <Pack>True</Pack>
      <PackagePath>lib$(TargetFramework)</PackagePath>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>

I tried this answer here, but I could not get it to work. I also tried changing the <PackagePath> for the .so file in the package file to app/, but that did not work.

Docker file looks like this. The nuget package is included in the STS project

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app

# copy csprojs and restore as distinct layers
WORKDIR /src
COPY ["./STS/STS.csproj", "STS/"]
COPY ["./Business/Business.csproj", "Business/"]
RUN dotnet restore "STS/STS.csproj"

# copy everything else and build
COPY . ./

WORKDIR "/src/STS"
RUN dotnet build "STS.csproj" -c Release -o /app/build -r linux-x64

FROM build AS publish
RUN dotnet publish "STS.csproj" -c Release -o /app/out -r linux-x64

# build runtime image
FROM mcr.microsoft.com/dotnet/sdk:8.0
WORKDIR /app
COPY --from=publish /app/out .
ENTRYPOINT ["dotnet", "STS.dll"]

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật