Skip to content

Latest commit

 

History

History
73 lines (62 loc) · 2.27 KB

File metadata and controls

73 lines (62 loc) · 2.27 KB

.NET 8 SDK extension

How to use

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"
},

Scripts

  • install.sh - copies dotnet runtime to package.
  • install-sdk.sh - copies dotnet SDK to package.

Publishing project

"build-commands": [
    "install.sh",
    "dotnet publish -c Release YourProject.csproj",
    "cp -r --remove-destination /run/build/YourProject/bin/Release/net8.0/publish/ /app/bin/",
]

Using nuget packages

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",
    "..."
]

Publishing self contained app and trimmed binaries

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