You need to add following lines to flatpak manifest:
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.dotnet9"
],
"build-options": {
"append-path": "/usr/lib/sdk/dotnet9/bin",
"append-ld-library-path": "/usr/lib/sdk/dotnet9/lib",
"prepend-pkg-config-path": "/usr/lib/sdk/dotnet9/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/net9.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 YourProject.csproj",
"cp -r --remove-destination /run/build/YourProject/bin/Release/net9.0/publish/ /app/bin/"
],
"sources": [
"sources.json",
"..."
]
.NET 9 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/dotnet9/bin/install.sh
.
First you need to have following lines in sources.json
. These packages are needed to build a project for specific runtime.
{
"type": "file",
"url": "https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.app.runtime.linux-arm64/9.0.11/microsoft.aspnetcore.app.runtime.linux-arm64.9.0.11.nupkg",
"sha512": "cfa9709633e91184bdd061951bf480e66da86175384e3a35ccc9ebbc768f207785807bc48628fd4101ecf6336a9495fbc9cb02aea3c0b9543c02e73fb96fb4f8",
"dest": "nuget-sources",
"dest-filename": "microsoft.aspnetcore.app.runtime.linux-arm64.9.0.11.nupkg",
"x-checker-data": {
"type": "html",
"url": "https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/9.0/latest.version",
"version-pattern": "^([\\d\\.a-z-]+)$",
"url-template": "https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.app.runtime.linux-arm64/$version/microsoft.aspnetcore.app.runtime.linux-arm64.$version.nupkg"
}
},
{
"type": "file",
"url": "https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.app.runtime.linux-x64/9.0.11/microsoft.aspnetcore.app.runtime.linux-x64.9.0.11.nupkg",
"sha512": "5373c5f77dc775544b72d4994101cac0618ca885518a44b928cd888086f9287f73a17af3642a6b017242beb6500e83ad68a3a7f9ebb217e832ebd0af781fa03b",
"dest": "nuget-sources",
"dest-filename": "microsoft.aspnetcore.app.runtime.linux-x64.9.0.11.nupkg",
"x-checker-data": {
"type": "html",
"url": "https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/9.0/latest.version",
"version-pattern": "^([\\d\\.a-z-]+)$",
"url-template": "https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.app.runtime.linux-x64/$version/microsoft.aspnetcore.app.runtime.linux-x64.$version.nupkg"
}
},
{
"type": "file",
"url": "https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.runtime.linux-arm64/9.0.11/microsoft.netcore.app.runtime.linux-arm64.9.0.11.nupkg",
"dest": "nuget-sources",
"dest-filename": "microsoft.netcore.app.runtime.linux-arm64.9.0.11.nupkg",
"x-checker-data": {
"type": "html",
"url": "https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/9.0/latest.version",
"version-pattern": "^([\\d\\.a-z-]+)$",
"url-template": "https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.runtime.linux-arm64/$version/microsoft.netcore.app.runtime.linux-arm64.$version.nupkg"
}
},
{
"type": "file",
"url": "https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.runtime.linux-x64/9.0.11/microsoft.netcore.app.runtime.linux-x64.9.0.11.nupkg",
"dest": "nuget-sources",
"dest-filename": "microsoft.netcore.app.runtime.linux-x64.9.0.11.nupkg",
"x-checker-data": {
"type": "html",
"url": "https://dotnetcli.blob.core.windows.net/dotnet/aspnetcore/Runtime/9.0/latest.version",
"version-pattern": "^([\\d\\.a-z-]+)$",
"url-template": "https://api.nuget.org/v3-flatcontainer/microsoft.netcore.app.runtime.linux-x64/$version/microsoft.netcore.app.runtime.linux-x64.$version.nupkg"
}
},
Then add build options:
"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 YourProject.csproj --runtime $RUNTIME --self-contained true",
"cp -r --remove-destination /run/build/YourProject/bin/Release/net9.0/$RUNTIME/publish/* /app/bin/",
],