Is EntityFrameworkCore.Sqlite embeddable in a self-contained single file application?

Viewed 297

I'm working on a CLI tool that I would like to be fully self-contained so the user can simply run the binary directly. It is currently using .NET 5 as well as Microsoft.EntityFrameworkCore.Sqlite version 5.0.0.

Replicating the behaviour is very easy:

  1. Create a new project with dotnet new
  2. Add EF Core sqlite with:
    dotnet add package Microsoft.EntityFrameworkCore.Sqlite
    
  3. Publish the app self-contained with:
    dotnet publish -r linux-x64 -p:PublishSingleFile=true --self-contained true -c Release -o publish
    

Now you will see the output directory will have 3 files:

libe_sqlite3.so
<project_name>.pdb
<project_name>

The two containing <project_name> are fine, but the libe_sqlite3.so one, which the application cannot run without, makes it not fully self-contained.

Provider and version information:

  • EF Core version: 5.0.0
  • Database provider: Microsoft.EntityFrameworkCore.Sqlite
  • Target framework: .NET 5.0
  • Operating system: Ubuntu 20.04
1 Answers

It is possible, as stated here:

Single-file doesn't bundle native libraries by default.

...

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.

In your case:

dotnet publish -r linux-x64 -p:PublishSingleFile=true --self-contained true -c Release -o publish /p:IncludeNativeLibrariesForSelfExtract=true

Related