Gigi Labs

Please follow Gigi Labs for the latest articles. Programmer's Ranch no longer has its domain, so please update your bookmarks and links to programmersranch.blogspot.com.

Wednesday, May 22, 2013

C#: Programming on Linux with MonoDevelop

Hello everyone! :)

C# is a language invented by Microsoft, and is normally used to create applications on Windows, using Visual Studio or, less commonly, SharpDevelop.

But as a matter of fact, it is also possible to write C# applications on Linux! There is a development environment similar to SharpDevelop, called MonoDevelop, which supports Linux development.

On a Debian-based system such as Kubuntu, you would open a terminal and install MonoDevelop using the following command:

sudo apt-get install monodevelop

If you have another flavour of Linux (e.g. based on Red Hat), you will need to use the appropriate package manager instead (e.g. rpm).

You can now launch MonoDevelop either by typing monodevelop in the terminal and pressing ENTER, or by finding it among your particular Linux distribution's applications (in the case of Kubuntu, via the K-menu).



From here, click Start New Solution... (see above).


Select "Console Project" from under C#. As with Visual Studio or SharpDevelop, you need to specify a name for the solution, and where you would like it to be created.


The next screen (above) is a bit weird. Just skip it by pressing the "OK" button.


You have now created your little console project, and MonoDevelop gives you sample code for a typical "Hello world" program. Press F5 to try and run it...


Well, that's not quite what we were expecting, right? We have a System.InvalidOperationException saying that "File name has not been set", but we have no clue how to fix it. Fortunately, though, someone has already bumped into this before, and the solution is simply to install xterm:

sudo apt-get install xterm

Once you install xterm, restart MonoDevelop. You can now debug your program to your heart's content:


Woohoo! :) This brief article showed you how to set up MonoDevelop on a Linux environment, and compile a basic application. You should now be able to go through just about any article at Programmer's Ranch so far using MonoDevelop if you like.

Note, however, that MonoDevelop can't do everything. For example, at the time of writing, it is simply not possible to get any WPF application working on Linux. However, MonoDevelop has some interesting alternatives such as Gtk# which I have yet to explore.

Happy coding, and stay tuned for more tutorials! :)

1 comment:

  1. I filed a bug report for the xterm dependency bug on Launchpad back in 2012:

    https://bugs.launchpad.net/ubuntu/+source/monodevelop/+bug/1090977

    It seems that this bug still shows up for some users, so I reopened it.

    ReplyDelete