.NET 5 excludes some libraries from single file publication

て烟熏妆下的殇ゞ 提交于 2020-12-31 16:46:54

问题


I have a little problem with single file executable publish with .NET 5.
Infact, it does not include all libraries in the executable file, and produces multiple files.

In my example I'm using a library for SQLite (Microsoft.Data.Sqlite) and, after compilation, e_sqlite3.dll is not included.
Instead, in the output folder, it produces two files (excluding the pdb file):

> e_sqlite3.dll
> WpfApp1.exe

回答1:


By reading 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.

So (in my case e_sqlite3.dll) native libraries are not included by default to ensure a good debugging experience.
If you want to include them anyway in the application executable, you can simply add this line to the project (.csproj) file.

<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>

Example:

<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>


来源:https://stackoverflow.com/questions/64778283/net-5-excludes-some-libraries-from-single-file-publication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!