Wednesday, January 7, 2015

How to Build C# Apps on Your Raspberry Pi

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.

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!

1 comment:

  1. I was searching for loan to sort out my bills& debts, then i saw comments about Blank ATM Credit Card that can be hacked to withdraw money from any ATM machines around you . I doubted thus but decided to give it a try by contacting {skylinktechnes@yahoo.com} they responded with their guidelines on how the card works. I was assured that the card can withdraw $5,000 instant per day & was credited with $50,000 so i requested for one & paid the delivery fee to obtain the card, i was shock to see the UPS agent in my resident with a parcel{card} i signed and went back inside and confirmed the card work's after the agent left. This is no doubts because i have the card & has made used of the card. This hackers are USA based hackers set out to help people with financial freedom!! Contact these email if you wants to get rich with this Via email skylinktechnes@yahoo.com whatsapp/t: +1(213)785-1553

    ReplyDelete