20

I would like to start learning C# and really want to code in it on my raspberry pi. However, I can't find a way to get C# onto my pi. Does anyone know how to do this? I have the Raspberry pi 2 model B. Thanks for your help.

1

5 Answers 5

12

'Mono' is a toolset and C# used to create “.NET” compatible programs based on Linux, and the resulting binaries are fully compatible with Microsoft.NET.

start from the Basic programs given in the link here which will definitely help you to understand ´mono´ better.

In Addition I have also used the documentation from the mono developers this which was very useful.

5
  • For this to work as a useful answer, can you please elaborate on the solution provided in the link? I.e. give a summary of the information and/or the next steps to take so that the OP does not have to click on the link to find out what your answer is about.
    – Phil B.
    Jan 25, 2016 at 12:54
  • 1
    The Details in the link are sufficent for the user to start from the Basics. I thought the user just needs Information to the question he posted. It doesn't make any sense to provide again a summary of the link. I don't understand the downvote for this!!
    – qwerty
    Jan 25, 2016 at 13:07
  • 2
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. See here Provide context for links Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline.
    – Ghanima
    Jan 25, 2016 at 13:19
  • 1
    @Ghanima Now that makes sense. I will edit it right away!!
    – qwerty
    Jan 25, 2016 at 13:21
  • 1
    To make this answer even more usefull it is best to use Jessie as the Mono packages are MUCH more up to date. wheezy is really out of data. You can also use Xamarin repository to get bleeding edge or RC, if you looking for the newest and most stable for things like webservers, threading and GUI
    – Piotr Kula
    Jan 25, 2016 at 17:32
10

I think you need to clarify what you are trying to achieve, but hopefully this will help.

Firstly, C# is a language. You write programs in C# and these will run on the .NET framework. It is the .NET framework that must be installed on your device for your C# program to run.

Since last year you have the option to install Windows 10 IoT Core on your Raspberry Pi 2. This is new technology so it is being actively developed and improving at a rapid pace, but there are a few limitations. You will need to use Visual Studio (Community Edition "free" version is fine) and you can currently only connect to a Pi2 from a Windows 10 computer. If you have these, then IMHO this is the best way to get C# running.

Alternatively there is the open source Mono Project which will run on Raspbian (and other flavours).

It will depend on your current skills as to which of these approaches will be best for you.

2
  • Using Visual Studio is great because of the debugging feature that is enabled when using IoT. There are also extensions for Visual Studio that enable you to debug C/C++ code on Raspbian (VisualGDB), now that is a killer extension that I use allot, in my favourite IDE :)
    – Piotr Kula
    Jan 25, 2016 at 17:35
  • 1
    Windows 10 IoT Core appears to be now available on Raspberry Pi 3: developer.microsoft.com/en-us/windows/iot/getstarted/prototype/… Mar 14, 2018 at 13:27
8

The answers referencing Mono are largely correct, but I would recommend as an alternative checking out .NET Core instead. .NET Core supports Raspbian as a deployment target. For more detailed information, check out the blog entry at https://blogs.msdn.microsoft.com/david/2017/07/20/setting_up_raspian_and_dotnet_core_2_0_on_a_raspberry_pi/, but to chunk out the "how to set it up" portion, you can obtain it by doing the following:

  • Run sudo apt-get install curl libunwind8 gettext. This will use the apt-get package manager to install three prerequiste packages.
  • Run curl -sSL -o dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Runtime/release/2.0.0/dotnet-runtime-latest-linux-arm.tar.gz to download the latest .NET Core Runtime for ARM32. This is refereed to as armhf on the Daily Builds page.
  • Run sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet to create a destination folder and extract the downloaded package into it.
  • Run sudo ln -s /opt/dotnet/dotnet /usr/local/bin` to set up a symbolic link...a shortcut to you Windows folks 😉 to the dotnet executable.
  • Test the installation by typing dotnet --help.

You can use any text editor to edit the C# programs and I have heard that VSCode will install, but I haven't been successful in getting that running yet.

1
  • Just what I was looking for... May 18, 2019 at 18:38
2

Mono is a C# compiler for Linux that you can download here. As for command line compiling, you would just need to run mono yourscript.exe as per this StackOverflow post.

1
  • Mono is CLR (middleware) that translates .NET to Linux.
    – Piotr Kula
    Jan 25, 2016 at 17:37
2

Install C sharp shell

$ sudo apt-get install mono-csharp-shell

Install MonoDevelop which is an IDE to help run C# on Pi

$ sudo apt-get install mono-runtime
$ sudo apt-get install mono-complete
$ sudo apt-get install monodevelop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.