"... and no one shall work for money, and no one shall work for fame; But each for the joy of the working, and each, in his separate star, shall draw the thing as he sees it, for the god of things as they are"

-Kipling

 

Installing MonoDevelop and Configuring a Remote Development Toolchain for the Raspberry Pi 2

Summary

This page describes how to install MonoDevelop on a remote PC running Ubuntu Linux for the purposes of configuring a C# remote compilation and debugging toolchain to the Raspberry Pi 2. This page is one part of a series of web pages which describe how to install C# and Mono on the Raspberry Pi 2 and also how to setup a useful remote compilation and debugging toolchain for it.

Installing MonoDevelop on the Linux Development PC

Note: In this section MonoDevelop will be installed on a remote PC running Ubuntu Linux. Later we will be able to compile a C# project on this PC and automatically transfer the compiled exe file over to the Raspberry Pi for execution. None of the commands in this section are to be executed on the Raspberry Pi unless you want to install MonoDevelop there.

Installing MonoDevelop is quite straight forward. I just followed the first few instructions on this page to get mono and mcs installed and then changed to using the advice from a different section of that page in later steps (see below) to get the latest MonoDevelop. You need to be the root user for this and rather than prefacing every command by sudo you may wish to just become the root user by issuing the sudo -s command once before starting.

First we need to ensure all of the installed packages and our build tools are up-to-date.

sudo apt-get install build-essential automake checkinstall intltool git

Now we get Mono and the C# compiler. As seems reasonable, MonoDevelop will need these in order to compile. Note that we are also getting the gtk toolkits so we can build and execute graphical packages. Any code written for these toolkits will also execute over on the Raspberry Pi for the simple reason that it has an identical set of GUI toolkits installed with its Mono runtime.

sudo apt-get install mono-complete mono-addins-utils gtk-sharp2 gnome-sharp2

At this point both mono and mcs should be installed on the development PC. As with the installation on the Raspberry Pi you can test out both of these from the command line. You can test mono by issuing the command mono -V. If installed correctly you should see the version display code appear. You can also type the command mcs -about on the command line to see if Mono C# compiler is there.

If you wish to test things out further you can build, compile and run some simple "Hello World" code. The nano editor can be used to create this (issue the command nano helloworld.cs) by copying the text below and pasting it in.

using System;
namespace Hello {
	class HelloWorld {
		public static void Main(string[] args) {
			Console.WriteLine("Hello World!");
		}
	}
}

Compiling the above code with the command mcs helloworld.cs and then running it with the command mono helloworld.exe should prove sucessful. If it does not then you probably want to fix this before moving on to the next step.

At this point gtk and gtk-sharp should also now be installed. For completeness sake you may wish to see if you can create a form based C# executable and get it to display. I created the file hellogtk.cs based on the information in the following link http://www.mono-project.com/docs/gui/gtksharp/hello-world/.

using Gtk;
using System;
 
class Hello {
        static void Main()
        {
                Application.Init ();
                Window window = new Window ("helloworld");
                window.Show();
                Application.Run ();
        }
}

using the nano editor. As before, I compiled it with the command mcs hellogtk.cs -pkg:gtk-sharp-2.0 and ran it with the command mono hellogtk.exe. It ran perfectly and popped up a little form window on the Ubuntu PC's desktop.

The Hello GTK Window

 

Now we need to install MonoDevelop. Following various advice towards the bottom of this web page I entered the commands

sudo add-apt-repository ppa:ermshiperete/monodevelop
sudo apt-get update
sudo apt-get install monodevelop-current

Once the above command completed, typing monodevelop on the command line simply claims the software is not installed. However it is installed and using the command /opt/monodevelop/bin/monodevelop-launcher.sh launches it. Once MonoDevelop started, I created a quick gtk#2.0 project from the MonoDevelop New Project Wizard, compiled and then ran that right out of the IDE and it too worked perfectly.

Adding MonoDevelop to the Toolbar

The previous step above required MonoDevelop to be launched via the command /opt/monodevelop/bin/monodevelop-launcher.sh. For no particular reason I decided that MonoDevelop should be available in the tool bar on the right hand side of the Ubuntu desktop. Turns out that this part of the GUI is called the Launcher. After a bit of digging, I followed the instructions on this page and made a monodevelop.desktop file with permission 755. Here is the file contents...

Version=1.0 
Name=MonoDevelop 
Comment=Develops C# software and runs it with mono 
Exec=/opt/monodevelop/bin/monodevelop-launcher.sh 
Icon=MonoDevelop 
Terminal=false 
Type=Application 
Categories=Application; 
I got a png MonoDevelop.png icon off the internet and placed it into /usr/shar/pixmaps with a command
sudo cp MonoDevelop.png /usr/share/pixmaps
which is why the icon name in a the above file needs neither a path or a filename extension.

The monodevelop.desktop file appears perfectly in the file browser and I also dragged and dropped it onto the launcher to get it to appear there.

Getting the Compiled Files from the Linux Development PC to the Raspberry Pi 2

The previous steps on this page have got us to the point where we can create and compile a C# project on the Ubuntu Linux PC and this will become our remote development environment. Executables created and compiled in MonoDevelop on the Linux Development PC will run on the Raspberry Pi. However we do not, at the moment, have any easy way to get those files over to the Raspberry Pi. Still, it is fun to try it out by using sftp (ftp will not work) to move a compiled exe file from the Linux Development PC to the Raspberry Pi 2 and run it there. This also works for exe files created in Visual Studio on a Windows PC. This, fundamentally, is the point of .NET - a binary compatible executable which runs on any platform. Try creating a simple "Hello World" .NET 4.0 console project in Visual Studio and transfer the resulting executable (PuTTY PSFTP works fine) to the Raspberry Pi 2. You will see that it runs there with no issues.

The next step in the process is to configure NFS to run on both the Raspberry Pi 2 and our Linux Development PC so that files compiled on the Development PC will automatically appear on the Raspberry Pi 2 the instant they are output thus eliminating the requirement to implement an awkward sftp step to transfer things. A mapped network drive is much simpler and really reduces the cycle time when developing code. For example, all you will ultimately need to do is press F8 on in MonoDevelop on the Development PC to compile and then go to a ssh terminal session connected to the Raspberry Pi 2 and run that exe with another single command. As we shall see, remote debugging is also similarly simple to use once we get it configured.

The next page in this series of pages discusses how to setup NFS on the Development PC and the Raspberry Pi 2 so a directory on the Development PC is visible on the Raspberry Pi.

License

The contents of this web page are provided "as is" without any warranty of any kind and without any claim to accuracy. Please be aware that the information provided may be out-of-date, incomplete, erroneous or simply unsuitable for your purposes. Any use you make of the information is entirely at your discretion and any consequences of that use are entirely your responsibility. All source code is provided under the terms of the MIT License.