1
votes

I wrote my HelloWorld.cs using MonoDevelop, and Gtk# 2.0. It runs fine in the debugger, and it builds HelloWorld.exe. When I run from a terminal window "mono ./HelloWorld.exe" then the program runs as expected so I know it is coded as expected. However when I attempt to run it by double clicking on it from Files (Linux version of Windows Explorer) it opens Archive Manager with an error "An error occurred while loading the archive".

I am using Ubuntu 18.04.02 LTS, if that makes a difference.

I tried creating a link "ln -s ./HelloWorld.exe ./meow", and double clicked on meow, however that also opens Archive Manager with the same error.

I don't want my end product to require the user to open a Terminal window to run my program, what do I do so that the user can double click on my program from Files to run?

EDIT: [18FEB2019] Thanks Some programmer dude, I like the bundle idea as I may port this project to a different flavor of linux and I hope this gives me a path to get there. However, I got error:

Failure to load i18n assemblies, the following directories were searched for the assemblies:
Path: .
In Custom mode, you need to provide the directory to lookup assemblies from using -L
ERROR: Couldn't load one or more of the i18n assemblies: Failed to load I18N.dll

I searched and found

 https://www.mono-project.com/docs/tools+libraries/tools/mkbundle/

I followed those directions and got stuck at this part

 mkbundle -o CacheServer --cross mono-5.8.0-ubuntu-16.04-x64 CacheServer.exe --machine-config /etc/mono/4.5/machine.config

my error is

 ERROR: Unable to load assembly `gtk-sharp' referenced by `/home/amccombs/Projects/HelloWorld/HelloWorld/bin/Debug/HelloWorld.exe'

I tried

mkbundle --fetch-target gtk-sharp

with result

Failure to download the specified runtime from https://download.mono-project.com/runtimes/raw/gtk-sharp

I then tried

sudo apt-get install gtk-sharp

with result

E: Unable to locate package gtk-sharp
1
This documentation is old, but might help get you on the right track? As might this newer documentation.Some programmer dude
Like @Someprogrammerdude mentions, you need to register the exe file extension as a non-native binary that is executed by mono. This might help also askubuntu.com/questions/20246/…muszeo
PS. you could try installing the latest monodevelop as well, from the command line, as this generally (not always in my experience) registers the exe extension for you. monodevelop.com/downloadmuszeo
I like the bundle idea, I would prefer bundle than to register, I added [18FEB2019] with more information, -thank you.user3554851

1 Answers

1
votes

Files is detecting the .exe extension as an archive, and therefore it opens it with File Roller or similar.

Just right-click the file HelloWorld.exe and select "Open With Other Application", click on "Find New Applications", and then type "mono" and press ENTER. The app will open.

Another possibility is to create a .desktopfile, and place it under ~/.local/share/applications, with this contents:

[Desktop Entry]
Exec=mono %F
MimeType=application/x-ms-dos-executable;
Name=mono
NoDisplay=true
Type=Application

MKBundle creates a native app from a mono application. The downside is that you have to compile both the app and all its dependencies, which can be tricky. In any case, the package you are looking for is gtk-sharp2.

An alternative to MKBundle is to include a text file, say HelloWorld.sh with the contents:

mono HelloWorld.exe

And then make it executable with:

chmod +x HelloWorld.sh

You can then pack both files together (use a .tar.gz target, which preserves attributes such as the executable one), and probably with a README file explaining to double-click HelloWorld.sh.

Or maybe you can pack the .exe with the .desktop file, and explain in the README file where it must be placed.

There are tons of possibilities.