Programming Blog

Jeremy Morgan

Mostly Coherent Ramblings of a Silicon Forest Software Developer

How to Build C# Apps on Your Raspberry Pi

Author: Jeremy Morgan

Raspberry Pi Newsletter

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.

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.

C# Newsletter

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:

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:


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.

Raspberry Pi Newsletter

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!

My New Course: Hands on Internet of Things with the Raspberry Pi

Internet of Things

I have just released my new course titled ”Hands on Internet of Things” which is intended to be a course for people who want to get started with IoT. I’ll take you through blinking lights and reading sensors to creating YOUR own IoT endpoint and dashboard. I’m offering this special coupon for readers of my site: get %50 off this course here. Thanks for being a reader!

Like my IoT projects? Sign up here to be added to my IoT newsletter