9

我最近一直在想办法解决这个问题。它在我的 Windows 机器上运行,我从 NuGet 获得了 SQLite,但是......

当我将我System.Data.SQLite.dllSQLite.Interop.dllWindows 机器直接放入 Linux 服务器时,它说SQLite.Interop.dll找不到,但我确信我看到它下一个可执行文件。

然后我尝试用 编译System.Data.SQLite.dll/p:UseInteropDll=false但没有运气。这次它说System.Data.SQLite.dll没有找到。

这个“未找到”的谜团是什么?

4

5 回答 5

12

无需更改代码。您可以自己构建它。

  1. apt-get install build-essentials unzip
  2. 下载 SQLITE 源代码 - 你想要完整的源代码。目前称为sqlite-netFx-full-source-1.0.104.0.zip
  3. unzipcd Source,
  4. chmod +xcompile-interop-assembly-release.sh构建 shell 脚本,然后运行它./compile-interop-assembly-release.sh。- 它将.so在目录中构建一个文件../bin
  5. .so将此文件复制到您的应用程序所在的目录
  6. 正常运行您的应用程序。
  7. 注意:确保您的 SQLite 数据库及其所在的目录可由您尝试运行的用户写入。
于 2017-04-02T20:31:05.303 回答
8

Mono.Data.SQLite.dll在 Linux 上使用。查看 Mono 手册以在 Linux 上使用 SQLite在 Mono 上构建 System.Data.SQLite.dll

您还可以映射 DLL:

<configuration>
  <dllmap dll="sqlite" target="libsqlite.so.0" os="linux"/>
  <dllmap dll="sqlite" target="libsqlite.0.dylib" os="osx"/>
  <dllmap dll="sqlite3" target="libsqlite3.so.0" os="linux"/>
  <dllmap dll="sqlite3" target="libsqlite3.0.dylib" os="osx"/>
</configuration>
于 2014-01-22T21:25:33.437 回答
5

我开始在 Windows 中进行开发,但随后将应用程序移至 Mono(Ubuntu 14),这是 SQLite 提供程序未能按照 OP 所述加载的地方。

我不得不使用以下命令重新编译 System.Data.SQLite.dll:

MSBuild System.Data.SQLite.2012.csproj /t:Rebuild /p:UseInteropDll=false /p:UseSqliteStandard=true 

但是,在此之后,我遇到了以下异常:

提供程序未返回 ProviderManifest 实例。方法System.Data.SQLite.UnsafeNativeMethods:GetSettingValue (string,string)' is inaccessible from methodSystem.Data.SQLite.EF6.SQLiteProviderManifest:GetProviderManifestToken (string)'

为了解决这个问题,我必须使用以下命令重新编译 System.Data.SQLite.EF6.dll:

MSBuild System.Data.SQLite.EF6.2012.csproj /t:Rebuild /p:UseInteropDll=false /p:UseSqliteStandard=true

将所有生成的文件复制到 Mono 项目的 bin 目录后,一切正常。

我使用的 SQLite 提供程序源代码版本是 1.0.98.1。

希望这可以节省很多时间...

于 2015-11-24T21:26:50.353 回答
3

我尝试了上述所有选项,但这些选项无法解决 SQLite DLL 问题,可能是因为我使用的是 ubuntu 18 版本,所以尝试了其他选项,这里是步骤,

1) 从https://system.data.sqlite.org/downloads/1.0.111.0/sqlite-netFx-full-source-1.0.111.0.zip下载 SQLite 源代码

2) 解压源码并cd到解压目录

3)在终端中运行以下命令,

xbuild /p:Configuration=Release /p:UseInteropDll=false /p:UseSqliteStandard=true ./System.Data.SQLite/System.Data.SQLite.2010.csproj

4)上面的命令将在以下路径创建一个dll文件,

sqlite-netFx-full-source-1.0.111.0/bin/2010/ReleaseMonoOnPosix/bin

5) 将 System.Data.SQLite.dll 复制到您的项目 bin 文件夹中。

6)清理项目并再次构建。

我希望这会有所帮助。

于 2019-07-16T09:53:33.013 回答
1

System.Data.SQLite.Core 1.0.109 开始,您不需要自己编译任何东西,因为本机SQLite.Interop.dll文件包含在所有平台(Linux、macOS 和 Windows)的 NuGet 包中。请注意,虽然dll扩展名用于所有平台,但文件实际上是本机动态库(通常在 macOS 和Linux上dylib为后缀)。

$ find ~/.nuget/packages/system.data.sqlite.core/1.0.111/runtimes -name SQLite.Interop.dll -print0 | xargs -0 file
…/runtimes/linux-x64/native/netstandard2.0/SQLite.Interop.dll: ELF 64-bit LSB pie executable x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=96ce4120b31bad7d95f7b9ccf7c4bbb7717ae0b1, with debug_info, not stripped
…/runtimes/osx-x64/native/netstandard2.0/SQLite.Interop.dll:   Mach-O 64-bit dynamically linked shared library x86_64
…/runtimes/win-x86/native/netstandard2.0/SQLite.Interop.dll:   PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
…/runtimes/win-x64/native/netstandard2.0/SQLite.Interop.dll:   PE32+ executable (DLL) (GUI) x86-64, for MS Windows

不幸的是,负责将本机动态库复制到输出目录的 MSBuild 目标仅适用于 Windows。这可能是因为该软件包的作者假设 .NET Framework 仅在 Windows 上运行,这要归功于 Mono。另外,如果你想看看,CopySQLiteInteropFiles目标可以在 中找到~/.nuget/packages/system.data.sqlite.core/{version}/build/net4*/System.Data.SQLite.Core.targets

但是可以自动将SQLite.Interop.dll文件复制到 Linux 和 macOS 上的输出目录中。FixSQLiteInteropFilesOnLinuxAndOSX在您的 csproj 文件中添加目标(如下所述),您将能够在没有DllNotFoundException. 这是您的项目的外观:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net452</TargetFramework>
  </PropertyGroup>
  <Target Name="FixSQLiteInteropFilesOnLinuxAndOSX" BeforeTargets="CopySQLiteInteropFiles">
    <ItemGroup>
      <SQLiteInteropFiles Condition="$([MSBuild]::IsOsPlatform(Linux)) OR $([MSBuild]::IsOsPlatform(OSX))" Remove="@(SQLiteInteropFiles)" />
      <SQLiteInteropFiles Condition="$([MSBuild]::IsOsPlatform(Linux))" Include="$(PkgSystem_Data_SQLite_Core)/runtimes/linux-x64/native/netstandard2.0/SQLite.Interop.*" />
      <SQLiteInteropFiles Condition="$([MSBuild]::IsOsPlatform(OSX))" Include="$(PkgSystem_Data_SQLite_Core)/runtimes/osx-x64/native/netstandard2.0/SQLite.Interop.*" />
    </ItemGroup>
  </Target>
  <ItemGroup>
    <PackageReference Include="System.Data.SQLite.Core" Version="1.0.111" GeneratePathProperty="true" />
  </ItemGroup>
</Project>

确保添加GeneratePathProperty="true"包参考。这是PkgSystem_Data_SQLite_Core要定义的属性所必需的。

于 2019-10-05T14:03:21.993 回答