部署ASP.NET Core Linux项目到树莓派:SQLite.Interop.dll无法识别
在树莓派3B(64位Raspbian Lite)部署ASP.NET Core 7应用时SQLite加载失败问题
我在Linux Mint环境下基于ASP.NET Core 7开发了一个轻量应用,编译目标为linux-arm64,计划部署到运行64位Raspbian Lite(.NET RID为linux-arm64)的树莓派3 Model B上。应用依赖SQLite3,但无论采用哪种编译方式,在树莓派上运行时都会抛出以下错误:
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'SQLite.Interop.dll' 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: /var/www/html/leafletasp/SQLite.Interop.dll.so: cannot open shared object file: No such file or directory /var/www/html/leafletasp/libSQLite.Interop.dll.so: cannot open shared object file: No such file or directory /var/www/html/leafletasp/SQLite.Interop.dll: cannot open shared object file: No such file or directory /var/www/html/leafletasp/libSQLite.Interop.dll: cannot open shared object file: No such file or directory
编译产物中缺少以下关键文件:
- System.Data.SQLite.Core对应文件
- Stub.System.SQLite.Core.NetStandard对应文件(netstandard.dll已存在)
- 所有SQLite.Interop相关文件
我已经尝试了以下多种解决方法,但均未消除上述错误:
- 编译为自包含应用,无论是否搭配ASP.NET运行时运行
- 编译为自包含单文件应用
- 采用默认非自包含编译,搭配ASP.NET运行时运行
- 安装并添加以下NuGet包到项目依赖:
- System.Data.SQLite
- Stub.System.Data.SQLite.Core.NetStandard
- System.Data.SQLite.Core
- System.Data.SQLite.EF6
- 在.csproj中添加
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>配置项 - 为所有SQLite相关包引用添加
PrivateAssets="none"属性 - 添加
<PackageReference Include="SQLite.Interop" Version="1.0.0"/>,但编译器警告该包与.NET 7 SDK不兼容(需从.NET Framework 4.8推断),添加后编译产物包含SQLite.Interop.dll,但运行时报错提示ELF头无效 - 在树莓派上通过apt安装最新版sqlite3和libsqlite3-dev包
我的项目.csproj文件内容如下:
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net7.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <RuntimeIdentifier>linux-arm64</RuntimeIdentifier> <SelfContained>true</SelfContained> <!-- does not appear to affect anything at all--> <ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles> <CopySQLiteInteropFiles>false</CopySQLiteInteropFiles> <CleanSQLiteInteropFiles>false</CleanSQLiteInteropFiles> <CollectSQLiteInteropFiles>false</CollectSQLiteInteropFiles> </PropertyGroup> <ItemGroup> <PackageReference Include="HtmlAgilityPack" Version="1.11.49" /> <PackageReference Include="Markdig" Version="0.31.0" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="SQLite.Interop.dll" Version="1.0.103" PrivateAssets="none"/> <PackageReference Include="Stub.System.Data.SQLite.Core.NetStandard" Version="1.0.118" PrivateAssets="none"/> <PackageReference Include="System.Data.SQLite" Version="1.0.118" PrivateAssets="none"/> <PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" PrivateAssets="none"/> <PackageReference Include="System.Data.SQLite.EF6" Version="1.0.118" PrivateAssets="none"/> </ItemGroup> <ItemGroup> <Folder Include="Views\" /> </ItemGroup> </Project>
目前暂不考虑Apache部署的问题,只希望程序能在树莓派上正常启动。
内容的提问来源于stack exchange,提问作者pilotguy772
相关产品推荐
相关产品推荐

