48

I know C# and I like to switch between systems and use Linux. Can I use C# to build applications that will natively work on Linux? What should I do to make use of my knowledge of C# in a Linux system?

Note that I'm specialized in Unity3D, but I still want to create Linux applications using C#.

  • 1
    KerbalSpaceProgram is written in Unity and runs on Win/Mac/Linux. Plugins/Mods to KSP are written in C# and can be developed on Win, Mac or Linux. I use primarily Mac now instead of Linux for $REASONS, but I do KSP mod development on that platform in C# and not windows. I'm likely going to write some stand-alone C# code with xUnit tests outside of KSP soon and it'll be just like any other development, but I'll just have to run it under mono. MechJeb has an example Makefile that builds on Mac+Linux: github.com/MuMech/MechJeb2/blob/master/Makefile (requires KSP game dlls to link). – lamont Apr 5 '18 at 20:18
  • 3
    C# applications don't usually run natively anywhere. – OrangeDog Apr 6 '18 at 11:13
  • @OrangeDog I know, even on Windows you need to install .Net framework. If i said "natively" i mean without any emulation or compatibility layer. I basically mean if Linux support it no matter how many programs or packages you need to install. – Jacob Apr 6 '18 at 13:08
  • 2
    What relevance does any of this have to Ubuntu? – underscore_d Apr 6 '18 at 15:58
  • 2
    @underscore_d I don't know where you heard that, but it's not true. See Are “not only Ubuntu-specific” questions on-topic? Many, many questions on Ask Ubuntu apply equally to the vast majority of GNU/Linux systems. Maybe someone will find a plausible reason to consider this question off-topic, but if so, it won't be that. (Btw, this does have answers with Ubuntu-specific information. The second paragraph of my own post is about Ubuntu packages; it carries over to some, but not all, other distros.) – Eliah Kagan Apr 7 '18 at 18:17
57

Most likely you will stumble upon http://www.mono-project.com/

As the About Mono page says:

Mono, the open source development platform based on the .NET Framework, allows developers to build cross-platform applications with improved developer productivity. Mono’s .NET implementation is based on the ECMA standards for C# and the Common Language Infrastructure.

The supported platforms include Linux.

| improve this answer | |
  • 2
    Mono... sound familiar... Oh yeah, this is what is unity based on ! I had no idea that i can use it separately. I thought it is part of Unity3d. – Jacob Apr 4 '18 at 18:12
  • 42
    The latest version of Microsoft's implementation (.Net Core) also supports Linux. – BlueRaja - Danny Pflughoeft Apr 4 '18 at 22:14
  • 6
    Mono implements .net standard 2.0 (iirc) not just core. – casey Apr 5 '18 at 3:27
  • 13
    This would have been a nice answer a few years ago. Now it’s pretty much obsolete. – Konrad Rudolph Apr 5 '18 at 15:13
  • 2
    If you are using a recent version of Ubuntu, please please please don't use mono, it has so many bugs and poor implementations, use .net core. Where I work, almost every issue we have when running C# applications on old linux distros can be explained with the statement: "because of mono". Exception filters losing stack traces, async implementations which are Task.Run wrappers, memory leaks all over the shot and lack of valgrind support so you can't even properly diagnose the leak. – Lukazoid Apr 7 '18 at 22:50
75

Yes, you can develop software on Ubuntu, that itself will run on Ubuntu, in C#. Both Mono and .NET Core support GNU/Linux systems like Ubuntu. (You can use them on other distros, too, like Debian, Raspbian, Fedora, CentOS, Arch, Gentoo, and so forth.) The Unity3D game engine also supports Ubuntu, as you probably know. Unity3D embeds Mono.

A number of packages for Ubuntu, installable with Ubuntu's package manager from officially community-supported software sources, are written in C# and use Mono. This includes the music player Banshee, the notetaking app Tomboy, the raster graphics editor Pinta, and the password manager KeePass (since version 2).

Most text editors, such as Gedit, Vim, and Emacs, have syntax highlighting for C#. MonoDevelop and Visual Studio Code are two popular integrated development environments that run on Ubuntu and support C# development.

| improve this answer | |
  • 10
    Maybe also mention Rider, the intellij idea-based IDE for C# that contains all the functionality of ReSharper for Visual Studio. – Wilbert Apr 5 '18 at 7:22
  • You may want to tune up this answer so it implies that other distributions of linux do exist. Since they will also provide or support mono, you may want to be a little more neutral and inclusive. – user2066657 Apr 6 '18 at 14:46
  • @user2066657 Thanks for the suggestion; I've edited. I had meant to make clear how Mono and .NET Core were not limited to Ubuntu ("GNU/Linux systems like Ubuntu"). But on further consideration, I realize this may not have been clear to readers who didn't already know what I was trying to tell them. So I've expanded that part. I do realize this edit may not satisfy you: I've made it more inclusive, but not more neutral. It's reasonable for posts on this site to emphasize Ubuntu. The middle part, giving examples of C# programs with downstream Ubuntu packages, is deliberately focused on Ubuntu. – Eliah Kagan Apr 6 '18 at 15:36
  • If the OP had wanted to ask about non-Ubuntu OSes, they would probably have asked in Unix & Linux. – Mr Lister Apr 6 '18 at 15:42
  • @MrLister Yes, agreed. But I think something is gained, and nothing lost, by the clarification I have added. I don't plan to retool the post as a whole, though. For example, I considered saying something about which distros MonoDevelop and Visual Studio Code are reasonably easy to install and use on, but decided against doing so, on the grounds that it's somewhat complicated and would end up changing the tone and focus (and length!) of the post. – Eliah Kagan Apr 6 '18 at 15:48
20
  1. You can now develop server applications on Linux using C# (.NET Core framework), like you can use Java or Python. By server applications I mean web applications and web service (REST) applications mostly. This makes a perfect match with Linux containers (Docker/K8s) and clouds.
  2. You can develop desktop applications with C# using the Mono Framework (a .NET implementation) and GTK# (GtkSharp) toolkit (a wrapper of GTK). There are many projects developed on it. This framework have had some resistance by part of the Linux's community in the past. Some distributions and users didn't want Mono applications.
  3. You can develop games with the Unity Engine using C# on Linux. Unity Editor is experimental on Linux yet.

So, yes. Knowledge on C# can be very useful on Linux systems today.

| improve this answer | |
  • 4
    You can also do desktop applications in .NET Core. – PmanAce Apr 5 '18 at 15:50
  • You can also use Avalonia, a cross platform WPF re-implementation to do mobile+desktop apps on Mac+Linux+Windows. Finally a non-garbage UI toolkit! – Chris Bordeman Nov 9 '19 at 6:34
2

You can now even do XAML based front end cross platform (Linux, Mac, Windows, Android, iOS, UWP) apps using .Net Core and a new project called Avalonia. Avalonia is in Beta, but works pretty well now. It is similar to WPF, but with some CSS like enhancements to styling.

I believe on Linux Avalonia targets Gtk currently, but they're wanting to move to something else. IT's mentioned in this video, but I personally couldn't understand what he said: https://www.youtube.com/watch?v=WESJUJWBLJ0

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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