【问题标题】:Eliminate "e_sqlite3.dll" during single file compilation单文件编译时去掉“e_sqlite3.dll”
【发布时间】:2022-12-03 07:55:51
【问题描述】:

在我尝试编译一个利用 Microsoft.Data.Sqlite 的单文件二进制文件时,我一直被留下两个文件这两者都是应用程序工作所必需的。

  1. {ProjectName}.exe
  2. e_sqlite3.dll

    是否可以将 e_sqlite3.dll 包含到 exe 中?

    看起来 System.Data.Sqlite 表现出相同的行为,但取而代之的是一个名为 SQLite.Interop.dll 的文件。

    示例代码

    注意:我意识到与 SQLite 没有实际的互操作发生,这段代码纯粹是为了演示编译。

    项目名称.fsproj

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net7.0</TargetFramework>
        <PublishSingleFile>true</PublishSingleFile>
        <SelfContained>true</SelfContained>
        <RuntimeIdentifier>win-x64</RuntimeIdentifier>
        <PublishReadyToRun>true</PublishReadyToRun>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="Microsoft.Data.Sqlite" version="7.*" />
      </ItemGroup>
      <ItemGroup>
        <Compile Include="Program.fs" />
      </ItemGroup>
    </Project>
    

    程序.fs

    module ProjectName.Program
    
    open System
    
    [<EntryPoint>]
    let main (argv : string[]) =
        printfn "Hello world"
        0
    

    编译工程如下:

    dotnet publish .\ProjectName.fsproj -c Release
    

【问题讨论】:

    标签: .net sqlite .net-core f# microsoft.data.sqlite


    【解决方案1】:

    不幸的是,似乎无法将 e_sqlite3.dll 包含到 exe 文件中。拥有单文件可执行文件的唯一方法是使用 .NET Native 工具链,可以通过将属性设置为 true 来启用它。

    【讨论】:

    • 谢谢!您是在谈论“本机 AOT”吗?
    • 不,.NET Native Toolchain 是一组工具和库,可用于将 .NET 应用程序编译为本机代码。本机 AOT(也称为提前编译)是一种编译类型,用于从托管代码生成本机代码。 .NET Native Toolchain 不执行 Native AOT,但它提供了必要的工具和库以允许其他编译器执行 Native AOT。
    • 明白了。恐怕这就是你的意思。叹息……我完全不相信在 2022 年要可靠地做到这一点有多么困难。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 2011-05-28
    • 2011-07-09
    • 1970-01-01
    • 2018-12-26
    • 2012-02-19
    相关资源
    最近更新 更多