Mono has a few environment variables that help make it portable, namely
MONO_GAC_PREFIX
MONO_PATH
MONO_CONFIG
You can make use of an environment stanza in your snapcraft.yaml
to help set these, e.g:
environment:
MONO_CONFIG: "$SNAP/etc/mono/config"
MONO_GAC_PREFIX: "$SNAP/usr/lib/mono/gac"
MONO_PATH: *ThisOneIsUniqueToYourSnapAndRequiresManualWork*
This comes from my work on the Pinta snap, which uses a newer upstream Mono version than provided in the Ubuntu repositories but I presume would likely work the same. In the dev builds which swapped to .NET 5
, I haven’t had to do any special work with environment variables, but whether that’s a result of Mono -> .NET or changes in the Pinta build environment I couldn’t tell you.
Regardless, if you search for all the locations of the dependent DLL in the snap you’d be able to specify them similar to my real world example like so:
MONO_PATH: "$SNAP/usr/lib/cli/atk-sharp-2.0:$SNAP/usr/lib/cli/gdk-sharp-2.0:$SNAP/usr/lib/cli/glib-sharp-2.0:$SNAP/usr/lib/cli/gtk-dotnet-2.0:$SNAP/usr/lib/cli/gtk-sharp-2.0:$SNAP/usr/lib/cli/Mono.Addins-0.2:$SNAP/usr/lib/cli/Mono.Addins.CecilReflector-0.2:$SNAP/usr/lib/cli/Mono.Addins.Gui-0.2:$SNAP/usr/lib/cli/Mono.Addins.Setup-0.2:$SNAP/usr/lib/cli/pango-sharp-2.0"
I also happen to have this layout defined, I can’t recall as to why, but presumably it’s relevant to snapping Mono applications.
layout:
/usr/lib/cli:
bind: $SNAP/usr/lib/cli
(Reference: https://github.com/MrCarroll/pinta-snap/blob/7fa04723b9f8f50d020596e5049acc09326705b6/snap/snapcraft.yaml)