Jeremy Morgan

My Blog about Programming, Tech, SEO, Marketing and whatever else I come up with.

How to Build C# Apps on Your Raspberry Pi


Author:


Want to run and build .Net applications on your Raspberry Pi? In this article I’ll show you how. With Mono you can develop and run .Net applications on your Raspberry Pi. I got a few emails about this, so I decided to create a quick tutorial.


Do you like my Rasbperry Pi Tutorials?

I’m constantly hacking on stuff with the Raspberry Pi. If you want to get notified every time I post a new article subscribe to my Raspberry Pi feed here, or you can Sign up for the Raspberry Pi Newsletter spam free!

What’s the Purpose here?

If you’re thinking of running your favorite Windows .Net applications, or setup a fancy ASP.NET server, you may be disappointed. While Mono does a great job and the Raspberry Pi performs great for what it is, I wouldn’t say this solution is ready for the big leagues, and definitely not something you want to do in a production or commercial environment.

If you want to tinker around and learn C#, and maybe build a few cool apps this is a great way to do it. The Raspberry Pi is a great tool for learning, and that’s the purpose of this project.

There are tons of MONO applications available in Raspbian but we’re only going to cover some basics.

Install Mono

Mono is an awesome project that brings .Net to Linux. It’s available for the Raspian image, and super easy to set up.

Update your repos:

sudo apt-get update

And install the Mono Runtime:

sudo apt-get install mono-runtime

This one could take a while. It updated a lot of stuff on my system.

sudo apt-get install mono-mcs

Note about MonoDevelop: You can install this on a soft float install of Raspian or Arch but it’s not the best performing application in these conditions. Mono still has a lot of problems with the Pi that need to be ironed out, and MonoDevelop is a long ways off.

Build a quick application.

Load up LeafPad (or whatever your favorite text editor is) and create a file called monotest.cs and save it somewhere where you’ll find it.

Enter the following code:

1
2
3
4
5
6
7
8
9
10
11
12
using System;

namespace Test
{
    class Program
    {
        public static void Main()
        {
            Console.WriteLine("Hello! This is a Mono app running on {0}", Environment.OSVersion);
        }
    }
}

Now, open up an LX Terminal and go to where this file is located (I just put it in a folder called monotest as well). Type in the following:

mcs monotest.cs

This should only take a couple seconds. Then list the files in your directory (using the ls command) you will see a new file:

monotest.cs
monotest.exe

Now, you can run the monotest.exe by typing in:

mono monotest.exe

You will see something like this:

And you’re ready to go! If you see this, that means it worked.

So what can you do now?

You can write basic C# console applications all day with this setup. You can build neat automation items, and even some GUI stuff if you really want to dig into it. You can write .Net 1.0 - 4.0 applications with varying success. The most valuable thing you do is learn some C# basics and experiment like crazy.

C# is one of my favorite languages, so it’s awesome to see options for playing with it without being forced to use Windows and Visual Studio, which are great tools but expensive for hobbyists. As I said this is nowhere near something for production use, but excellent for tinkering and learning which is of course what the Raspberry Pi is all about!


Do you like my Rasbperry Pi Tutorials?

I’m constantly hacking on stuff with the Raspberry Pi. If you want to get notified every time I post a new article subscribe to my Raspberry Pi feed here, or you can Sign up for the Raspberry Pi Newsletter spam free!

Comments