When using dotnet ef migrations bundle to create a bundle for the linux-x64 runtime, I encounter an exception due to missing the libhostpolicy.dylib library. This same exception happens when running on an M1 Mac or on Windows machine.
Attempted fixes
I tried including a runtimeconfig.json file per this Stack Overflow post - but as you can see in the repro, it doesn't make a difference.
I also tried specifying expected outputs via the DatabaseMigrator csproj file per various StackOverflow suggestions; none of them helped.
dotnet ef migrations bundle --runtime linux-x64 --verbose
dotnet ef migrations bundle --runtime linux-x64 --self-contained --verbose
dotnet ef migrations bundle --runtime linux-x64 --framework net6.0 --self-contained --verbose
Include verbose output
From M1 Mac on Monterey 12.6
dotnet ef migrations bundle --runtime linux-x64 --framework net6.0 --force --self-contained --verbose
Using project '/Users/alix/RiderProjects/WebTest/DatabaseMigrator/DatabaseMigrator.csproj'.
Using startup project '/Users/alix/RiderProjects/WebTest/DatabaseMigrator/DatabaseMigrator.csproj'.
Writing '/Users/alix/RiderProjects/WebTest/DatabaseMigrator/obj/DatabaseMigrator.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/var/folders/cx/_rnkr0gx6qq46zfw1zzxd1lh0000gn/T/tmpad7AeH.tmp /verbosity:quiet /nologo /Users/alix/RiderProjects/WebTest/DatabaseMigrator/DatabaseMigrator.csproj
Writing '/Users/alix/RiderProjects/WebTest/DatabaseMigrator/obj/DatabaseMigrator.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/var/folders/cx/_rnkr0gx6qq46zfw1zzxd1lh0000gn/T/tmp0zlnBh.tmp;TargetFramework=net6.0;RuntimeIdentifier=linux-x64 /verbosity:quiet /nologo /Users/alix/RiderProjects/WebTest/DatabaseMigrator/DatabaseMigrator.csproj
Build started...
dotnet build /Users/alix/RiderProjects/WebTest/DatabaseMigrator/DatabaseMigrator.csproj --framework net6.0 --runtime linux-x64 /verbosity:quiet /nologo
/usr/local/share/dotnet/sdk/6.0.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1114,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [/Users/alix/RiderProjects/WebTest/DatabaseMigrator/DatabaseMigrator.csproj]
/usr/local/share/dotnet/sdk/6.0.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1114,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [/Users/alix/RiderProjects/WebTest/WebTest/WebTest.csproj]
Build succeeded.
/usr/local/share/dotnet/sdk/6.0.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1114,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [/Users/alix/RiderProjects/WebTest/DatabaseMigrator/DatabaseMigrator.csproj]
/usr/local/share/dotnet/sdk/6.0.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(1114,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [/Users/alix/RiderProjects/WebTest/WebTest/WebTest.csproj]
2 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.59
Build succeeded.
dotnet exec --depsfile /Users/alix/RiderProjects/WebTest/DatabaseMigrator/bin/Debug/net6.0/linux-x64/DatabaseMigrator.deps.json --additionalprobingpath /Users/alix/.nuget/packages --runtimeconfig /Users/alix/RiderProjects/WebTest/DatabaseMigrator/bin/Debug/net6.0/linux-x64/DatabaseMigrator.runtimeconfig.json /Users/alix/.dotnet/tools/.store/dotnet-ef/6.0.0-preview.7.21378.4/dotnet-ef/6.0.0-preview.7.21378.4/tools/netcoreapp3.1/any/tools/netcoreapp2.0/any/ef.dll migrations bundle --force --self-contained --assembly /Users/alix/RiderProjects/WebTest/DatabaseMigrator/bin/Debug/net6.0/linux-x64/DatabaseMigrator.dll --project /Users/alix/RiderProjects/WebTest/DatabaseMigrator/DatabaseMigrator.csproj --startup-assembly /Users/alix/RiderProjects/WebTest/DatabaseMigrator/bin/Debug/net6.0/linux-x64/DatabaseMigrator.dll --startup-project /Users/alix/RiderProjects/WebTest/DatabaseMigrator/DatabaseMigrator.csproj --project-dir /Users/alix/RiderProjects/WebTest/DatabaseMigrator/ --root-namespace DatabaseMigrator --language C# --nullable --working-dir /Users/alix/RiderProjects/WebTest/DatabaseMigrator --verbose
A fatal error was encountered. The library 'libhostpolicy.dylib' required to execute the application was not found in '/Users/alix/RiderProjects/WebTest/DatabaseMigrator/bin/Debug/net6.0/linux-x64/'.
Failed to run as a self-contained app.
- The application was run as a self-contained app because '/Users/alix/RiderProjects/WebTest/DatabaseMigrator/bin/Debug/net6.0/linux-x64/DatabaseMigrator.runtimeconfig.json' did not specify a framework.
- If this should be a framework-dependent app, specify the appropriate framework in '/Users/alix/RiderProjects/WebTest/DatabaseMigrator/bin/Debug/net6.0/linux-x64/DatabaseMigrator.runtimeconfig.json'.
On Windows 11
dotnet ef migrations bundle --runtime linux-x64 --self-contained --verbose
Using project 'W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\DatabaseMigrator.csproj'.
Using startup project 'W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\DatabaseMigrator.csproj'.
Writing 'W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\obj\DatabaseMigrator.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\alastair\AppData\Local\Temp\tmp3B0E.tmp /verbosity:quiet /nologo W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\DatabaseMigrator.csproj
Writing 'W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\obj\DatabaseMigrator.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\alastair\AppData\Local\Temp\tmp3CF4.tmp;RuntimeIdentifier=linux-x64 /verbosity:quiet /nologo W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\DatabaseMigrator.csproj
Build started...
dotnet build W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\DatabaseMigrator.csproj --runtime linux-x64 /verbosity:quiet /nologo
C:\Program Files\dotnet\sdk\7.0.100-rc.1.22431.12\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1136,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\DatabaseMigrator.csproj]
Build succeeded.
C:\Program Files\dotnet\sdk\7.0.100-rc.1.22431.12\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1136,5): warning NETSDK1179: One of '--self-contained' or '--no-self-contained' options are required when '--runtime' is used. [W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\DatabaseMigrator.csproj]
1 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.88
Build succeeded.
dotnet exec --depsfile W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\bin\Debug\net6.0\linux-x64\DatabaseMigrator.deps.json --additionalprobingpath C:\Users\alastair\.nuget\packages --runtimeconfig W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\bin\Debug\net6.0\linux-x64\DatabaseMigrator.runtimeconfig.json C:\Users\alastair\.dotnet\tools\.store\dotnet-ef\6.0.10\dotnet-ef\6.0.10\tools\net6.0\any\tools\netcoreapp2.0\any\ef.dll migrations bundle --self-contained --assembly W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\bin\Debug\net6.0\linux-x64\DatabaseMigrator.dll --project W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\DatabaseMigrator.csproj --startup-assembly W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\bin\Debug\net6.0\linux-x64\DatabaseMigrator.dll --startup-project W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\DatabaseMigrator.csproj --project-dir W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\ --root-namespace DatabaseMigrator --language C# --framework net6.0 --nullable --working-dir W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator --verbose
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\bin\Debug\net6.0\linux-x64\'.
Failed to run as a self-contained app.
- The application was run as a self-contained app because 'W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\bin\Debug\net6.0\linux-x64\DatabaseMigrator.runtimeconfig.json' did not specify a framework.
- If this should be a framework-dependent app, specify the appropriate framework in 'W:\src\minimal-libhostpolicy.dylib-repro\DatabaseMigrator\bin\Debug\net6.0\linux-x64\DatabaseMigrator.runtimeconfig.json'.
Include provider and version information
EF Core version: "Microsoft.EntityFrameworkCore" Version="6.0.6"
Database provider: "Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6"
Target framework: .NET 6.0
Operating system: M1 Mac on Monterey 12.6; Windows 11
IDE: Rider, but the issue is triggered via the command line
File a bug
When using
dotnet ef migrations bundle
to create a bundle for thelinux-x64
runtime, I encounter an exception due to missing thelibhostpolicy.dylib
library. This same exception happens when running on an M1 Mac or on Windows machine.Attempted fixes
I tried including a runtimeconfig.json file per this Stack Overflow post - but as you can see in the repro, it doesn't make a difference. I also tried specifying expected outputs via the
DatabaseMigrator
csproj file per various StackOverflow suggestions; none of them helped.Include your code
I've made a small project to reproduce - https://github.com/evolutionise/minimal-libhostpolicy.dylib-repro. In order to get the same exception, run any of the below commands inside the
DatabaseMigrator
project directory.Include verbose output
From M1 Mac on Monterey 12.6
On Windows 11
Include provider and version information
EF Core version: "Microsoft.EntityFrameworkCore" Version="6.0.6" Database provider: "Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.6" Target framework: .NET 6.0 Operating system: M1 Mac on Monterey 12.6; Windows 11 IDE: Rider, but the issue is triggered via the command line