You need to add following lines to flatpak manifest:
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.dotnet8"
],
"build-options": {
"append-path": "/usr/lib/sdk/dotnet8/bin",
"append-ld-library-path": "/usr/lib/sdk/dotnet8/lib",
"prepend-pkg-config-path": "/usr/lib/sdk/dotnet8/lib/pkgconfig"
},
install.sh
- copies dotnet runtime to package.install-sdk.sh
- copies dotnet SDK to package.
"build-commands": [
"install.sh",
"dotnet publish -c Release YourProject.csproj",
"cp -r --remove-destination /run/build/YourProject/bin/Release/net8.0/publish/ /app/bin/",
]
If you want to use nuget packages it is recommended to use the Flatpak .NET Generator tool. It generates sources file that can be included in manifest.
"build-commands": [
"install.sh",
"dotnet publish -c Release --source ./nuget-sources --source /usr/lib/sdk/dotnet8/nuget/packages YourProject.csproj",
"cp -r --remove-destination /run/build/YourProject/bin/Release/net8.0/publish/ /app/bin/"
],
"sources": [
"sources.json",
"..."
]
.NET 8 gives option to include runtime in published application and trim their binaries. This allows you to significantly reduce the size of the package and get rid of /usr/lib/sdk/dotnet8/bin/install.sh
.
Slightly modify the build-commands
and add the build-options
as follows:
"build-options": {
"arch": {
"aarch64": {
"env" : {
"RUNTIME": "linux-arm64"
}
},
"x86_64": {
"env" : {
"RUNTIME": "linux-x64"
}
}
}
},
"build-commands": [
"mkdir -p /app/bin",
"dotnet publish -c Release --source ./nuget-sources --source /usr/lib/sdk/dotnet8/nuget/packages YourProject.csproj --runtime $RUNTIME --self-contained true",
"cp -r --remove-destination /run/build/YourProject/bin/Release/net8.0/$RUNTIME/publish/* /app/bin/",
],
Note that your nuget packages directory is listed before the one provided with the SDK, the build may fail if ordered differently.