wpf - .NET 5 从单个文件发布中排除了一些库

标签 wpf sqlite .net-5 single-file

我在使用 .NET 5 发布单个文件可执行文件时遇到了一些问题。
事实上,它不包括可执行文件中的所有库,而是生成多个文件。
在我的示例中,我使用的是 SQLite (Microsoft.Data.Sqlite) 库,并且在编译后,不包括 e_sqlite3.dll。
相反,在输出文件夹中,它生成两个文件(不包括 pdb 文件):

> e_sqlite3.dll
> WpfApp1.exe

最佳答案

通过阅读 documentation

Single-file doesn't bundle native libraries by default. On Linux, we prelink the runtime into the bundle and only application native libraries are deployed to the same directory as the single-file app. On Windows, we prelink only the hosting code and both the runtime and application native libraries are deployed to the same directory as the single-file app. This is to ensure a good debugging experience, which requires native files to be excluded from the single file. There is an option to set a flag, IncludeNativeLibrariesForSelfExtract, to include native libraries in the single file bundle, but these files will be extracted to a temporary directory in the client machine when the single file application is run.


因此(在我的例子中是 e_sqlite3.dll)默认情况下不包含 native 库以确保良好的调试体验。
如果您想在应用程序可执行文件中包含它们,只需将此行添加到项目 (.csproj) 文件中即可。
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
例子:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
    <StartupObject>WpfApp1.App</StartupObject>
    <Description>WpfApp1</Description>
  </PropertyGroup>

...

</Project>

关于wpf - .NET 5 从单个文件发布中排除了一些库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64778283/

相关文章:

c# - Blazor InputText、HTML Input 和直接从 C# 代码分配之间的差异

c# - 在 C# 中,是否可以强制 Clipboard.GetData 在每个 CSV 值周围输出引号?

sqlite - 转储不带自动生成列(例如 id)的 SQLite 表/数据库

java - Android Sqlite 数据库在执行批量插入时被锁定

azure - 将面向新版本 .NET 的 ASP.NET Core 应用部署到现有的 Azure 应用服务?

wpf - 如何在构建时使 .dll 和其他文件远离更深文件夹中的 .exe 文件?

c# - Windows 11 下的 WPF C# MoveWindow 问题

c# - 如果需要,显示 WPF 工具提示

WPF 上下文菜单未绑定(bind)到正确的数据绑定(bind)项

java - Android SQlite数据检索错误