0

I have a GUI application written in C# with GTK#, and I would like to publish it in a portable format, without requiring the user install any sort of GTK, GTK#, .NET, or Mono runtimes or libraries on their system.

It is important that this application can be used on machines where installing such software may not be possible - one example of this is on school hardware, as it is in essence a school project that I want to be able to run (not necessarily develop) at school.

Of course, this would need to be cross-platform.

This similar question from 2009 received an answer which suggested including the GTK# installer within the application's installer. Ideally, I do not want my program to have an installer of any kind (see my previous point on school hardware - this would not be viable). This would also defeat the purpose of the application being portable.

Another question from 2011 looked more promising, and its answer suggested, among other options, embedding the runtime into the application - this, according to the answer, should gain the results I'm looking for. However, since the answer is now more than a decade old... is this outdated advice? Is there a better way?

Regarding the possibility of embedding the Mono runtime into the application, how would I go about doing this? The answer linked to this guide, but it wasn't very clear to me, so maybe there are other resources I've missed?

kosude
  • 177
  • 3
  • 14

1 Answers1

0

This can be achieved using .NET 6 (or 5 if you wish) and the GTK3 .NET nuget libraries, and then using dotnet to publish your app as a single file. If you are using GTK# with .NET 4.8 or below, or Mono, then you can migrate from this to .NET 6.0 and GTK3 -- but, depending on your code, this may take you a while. The migration from .NET 4.8 to .NET 6.0 is mostly trivial; the migration from GTK# (which is GTK2 based) to GTK3 is more involved. But -- have hope -- it is doable.

The nuget libraries to get are v3.24+ of GdkSharp, GLibSharp, GtkSharp, and possible CairoSharp and PangoSharp.

I have an application that was originally in GTK# (GTK2, Mono) and is now GTK3 and .NET 6. The source code is open source and publicly available if you want to view how this is structured (https://continuity.nz/Downloads/Continuity%20v22.74-377%20Source.zip).

Important Notes:

  • On Windows I have been able to publish a single file for all of the .NET libraries, but not the GTK3 C dependencies. I have solved for this by including the GTK3 libraries in the distributed package (with license file).

  • On Mac OS I've not yet been able to figure out how to include the GTK3 C libraries in the distribution, so I have had to provide instructions on using brew to install.

  • On Linux, the usual availability of GTK3 in a gnome desktop environment means the single-file app "just works" without the need to distribute any C libraries with it.

  • There's no designer plugin to Visual Studio or Mono Develop for the forms, so you'll have to get used to creating these by hand.

  • I have found some stability issues with the GTK3 implementation on Mac, in particular pointers seem to get left out in the cold when using certain widgets, but you may not come across this.

Any further questions, if you embark on this journey, please do reach out. I may have answer having been down this path before.

muszeo
  • 2,312
  • 9
  • 13