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.

Jacobm001
  • 11,904
  • 7
  • 47
  • 58
John Quincy
  • 313
  • 1
  • 2
  • 6

5 Answers5

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.

qwerty
  • 326
  • 1
  • 13
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.

techraf
  • 4,353
  • 10
  • 32
  • 43
Mark Cooper
  • 531
  • 1
  • 4
  • 12
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.

Kyle Burns
  • 181
  • 1
  • 2
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.

Patrick Cook
  • 6,365
  • 8
  • 38
  • 63
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
Aurora0001
  • 6,357
  • 3
  • 25
  • 39
mark
  • 121
  • 4