Ubuntu – Running a mono program without typing in ‘mono foo.exe’

mono

When running a .net program on Ubuntu I have to type in "mono foo.exe" instead of just foo.exe or double-clicking the icon. Is there any way to just run foo.exe?

Best Answer

Does this link help? Running Mono

From the Mono Project on using binfmt:

Registering .exe as non-native binaries (Linux only)

Because this is a Linux-specific feature, we do not recommend that developers deploy this solution, as it would limit the portability of their scripts.

In addition, this mechanism does not work as intended by the Application Deployment Guidelines.

You can also make a systemwide change, and use binfmt to register the exe files as non-native binaries. Then, when trying to launch an exe file, the kernel will run the mono interpreter to handle the command. Binfmt can also be used to launch Windows executables using WINE, or Java .class files using a JVM. To register exe with the kernel:

Become root and turn on the binfmt module in your kernel with this command:

sudo apt-get install binfmt-support
modprobe binfmt_misc

In addition, you may want to add the modprobe command to your /etc/rc.local boot script, so that it will be executed on boot.

Add the line below to your /etc/fstab file:

binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc none

Then, have your system run the following command on boot:

echo ':CLR:M::MZ::/usr/bin/mono:' > /proc/sys/fs/binfmt_misc/register

Be sure to mark your .exe files as executable in the filesystem as well:

chmod +x myprogram.exe

Note that this doesn't change your kernel, just the modules that it loads when you boot your system. In other words, you can still upgrade your kernel without worrying about losing these changes. Similarly, you can upgrade your Mono runtime without affecting any of the invocation methods listed in this section.

Related Question