|
| 1 | +Dotnet |
| 2 | +====== |
| 3 | + |
| 4 | +Prerequisites |
| 5 | +~~~~~~~~~~~~~ |
| 6 | +- :doc:`first-build` |
| 7 | +- The application is built with a Linux-compatible .NET desktop application framework such as: |
| 8 | + - `Avalonia UI <https://avaloniaui.net/>`_ |
| 9 | + - `Uno Platform <https://platform.uno/>`_ |
| 10 | + - `Eto <https://github.com/picoe/Eto>`_ |
| 11 | + - `GTKSharp <https://github.com/GtkSharp/GtkSharp>`_ |
| 12 | +- The application's source code is hosted on a Git server such as GitHub, GitLab, or Bitbucket |
| 13 | + |
| 14 | +Steps for Packaging |
| 15 | +~~~~~~~~~~~~~~~~~~~ |
| 16 | + |
| 17 | +Installing Flatpak and Flatpak builder |
| 18 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 19 | + |
| 20 | +1. Install Flatpak using the method provided for your distribution |
| 21 | + `Flatpak - Quick Setup <https://flatpak.org/setup/>`_ |
| 22 | + |
| 23 | +2. Install Flatpak Builder through your distribution package manager (e.g. ``apt`` / ``dnf``) |
| 24 | + |
| 25 | +.. code-block:: shell |
| 26 | +
|
| 27 | + sudo apt install flatpak-builder |
| 28 | +
|
| 29 | +
|
| 30 | +Creating the Flatpak |
| 31 | +^^^^^^^^^^^^^^^^^^^^ |
| 32 | + |
| 33 | +A few placeholders have been used in the steps below, while going through the steps replace these with the ones respective to your project: |
| 34 | + |
| 35 | +- ``<app-id>``: The name of your Flatpak, see :ref:`conventions:application ids`. |
| 36 | +- ``<app-name>``: The name of the root folder of your app repository |
| 37 | +- ``<project-name>``: The name of your ``.csproj`` file |
| 38 | +- ``<git-url>``: The URL to the git repository of the project |
| 39 | + |
| 40 | +3. Create a new folder somewhere different from your existing project |
| 41 | + |
| 42 | +4. Create a YAML file titled ``<app-id>.yaml`` with the following example template, replacing the placeholders with the appropriate information. (Note: If your project file lives in a subfolder, be sure to include that in the build paths in this file and subsequent commands as well.): |
| 43 | + |
| 44 | +.. code-block:: yaml |
| 45 | +
|
| 46 | + id: <app-id> |
| 47 | + runtime: org.freedesktop.Platform |
| 48 | + runtime-version: '23.08' |
| 49 | + sdk: org.freedesktop.Sdk |
| 50 | + sdk-extensions: |
| 51 | + - org.freedesktop.Sdk.Extension.dotnet8 |
| 52 | + build-options: |
| 53 | + prepend-path: "/usr/lib/sdk/dotnet8/bin" |
| 54 | + append-ld-library-path: "/usr/lib/sdk/dotnet8/lib" |
| 55 | + prepend-pkg-config-path: "/usr/lib/sdk/dotnet8/lib/pkgconfig" |
| 56 | +
|
| 57 | + command: <project-name> |
| 58 | +
|
| 59 | + finish-args: |
| 60 | + - --device=dri |
| 61 | + # TODO: Replace this with wayland and fallback-x11 once Wayland support |
| 62 | + # becomes available: |
| 63 | + # https://github.com/AvaloniaUI/Avalonia/pull/8003 |
| 64 | + - --socket=x11 |
| 65 | + - --share=ipc |
| 66 | + - --env=DOTNET_ROOT=/app/lib/dotnet |
| 67 | +
|
| 68 | + modules: |
| 69 | + - name: dotnet |
| 70 | + buildsystem: simple |
| 71 | + build-commands: |
| 72 | + - /usr/lib/sdk/dotnet8/bin/install.sh |
| 73 | +
|
| 74 | + - name: <app-name> |
| 75 | + buildsystem: simple |
| 76 | + sources: |
| 77 | + - type: git |
| 78 | + url: <git-url> |
| 79 | + - ./nuget-sources.json |
| 80 | + build-commands: |
| 81 | + - dotnet publish <project-name>.csproj -c Release --no-self-contained --source ./nuget-sources |
| 82 | + - mkdir -p ${FLATPAK_DEST}/bin |
| 83 | + - cp -r bin/Release/net8.0/publish/* ${FLATPAK_DEST}/bin |
| 84 | +
|
| 85 | +.. note:: |
| 86 | + |
| 87 | + For providing access to other things such as the network or |
| 88 | + filesystem, see :doc:`sandbox-permissions` |
| 89 | + |
| 90 | +5. Copy and save the dotnet NuGet sources generator script |
| 91 | + ``flatpak-dotnet-generator.py`` from the `Flatpak Builder Tools |
| 92 | + repository <https://github.com/flatpak/flatpak-builder-tools>`_, to |
| 93 | + the current folder, or run the following command to download it: |
| 94 | + |
| 95 | +.. code-block:: shell |
| 96 | +
|
| 97 | + wget https://raw.githubusercontent.com/flatpak/flatpak-builder-tools/master/dotnet/flatpak-dotnet-generator.py |
| 98 | +
|
| 99 | +6. Clone down your project repository to the folder |
| 100 | + |
| 101 | +.. code-block:: shell |
| 102 | +
|
| 103 | + git clone <git-url> |
| 104 | +
|
| 105 | +7. Install dependencies from Flathub |
| 106 | + |
| 107 | +.. code-block:: shell |
| 108 | +
|
| 109 | + flatpak-builder build-dir --user --install-deps-from=flathub --download-only <app-id>.yaml |
| 110 | +
|
| 111 | +8. Run the NuGet source config generator script ``flatpak-dotnet-generator.py`` with the following arguments: |
| 112 | + |
| 113 | +.. code-block:: shell |
| 114 | +
|
| 115 | + python3 flatpak-dotnet-generator.py --dotnet 8 --freedesktop 23.08 nuget-sources.json <app-name>/<project-name>.csproj |
| 116 | +
|
| 117 | +9. Build and install using Flatpak builder |
| 118 | + |
| 119 | +.. code-block:: shell |
| 120 | +
|
| 121 | + flatpak-builder build-dir --user --force-clean --install --repo=repo <app-id>.yaml |
| 122 | +
|
| 123 | +
|
| 124 | +Testing the build |
| 125 | +^^^^^^^^^^^^^^^^^ |
| 126 | + |
| 127 | +10. Run the installed Flatpak application |
| 128 | + |
| 129 | +.. code-block:: shell |
| 130 | +
|
| 131 | + flatpak run <app-id> |
| 132 | +
|
0 commit comments