C#

Setting Up for Mono Development in Linux Mint/Ubuntu


Image by Neil Fowler  | Some Rights Reserved

I recently needed to create a cross-platform C# library which needs to work across Windows, OSX, and Linux. Obviously, getting a .NET library running on Windows presented no great difficulties. Getting the same library working under Mono on a Linux platform was a little more involved.

The folks at Xamarin have brought Mono, and the development tools available for Mono, a long ways. Xamarin Studio is a beautiful IDE which, while it differs from Visual Studio in some important ways, is a joy to work with. Xamarin’s focus is building mobile application development tools. However, Xamarin Studio and Mono both lend themselves fairly well to working with C# code on either Windows or OSX.

There are some notable things missing (you can’t work directly with Windows Forms, for example, nor is there significant support for ASP.NET), but overall, working with strictly library code presented only minor hurdles (not the least of which is a different workflow and navigation scheme from VS).

However, Xamarin Studio is only available for Windows and OSX – there is not currently any support for direct Linux platforms (yes, I know a shiny veneer on top of what amounts to Linux under the hood).

Getting things working on my Linux machine took a little more work.

Mono Development on Linux Using MonoDevelop

Xamarin Studio represents a “Super-Set” of the original, cross-platform Mono IDE, MonoDevelop. The Xamarin team have generously pushed a good number of improvements back to the MonoDevelop source. However, the most recent changes are not directly available as packages to all Linux distros.

Specifically, while the most recent version of MonoDevelop is 5.0.1.3, the most recent package available to Ubuntu, and Ubuntu-based systems from the MonoDevelop site is version 2.6.0.1.

In this article, we will look at how to get a proper Mono development environment set up on Ubuntu-based systems, including the most recent (as of this writing) release of MonoDevelop. We will also look at getting Nuget, and Nuget package restore, working properly in this environment.

Got Linux?

If you don’t have a Linux box, set up a VM to work through this post. I prefer using Linux Mint for my Linux-based activity. I found that all of the following steps worked fine in the most recent version of Ubuntu. However, I DON’T like Ubuntu itself. I prefer Linux mint. The last version of Mint I was using (Mint 13 with the KDE desktop) did not work very well with the most recent version of MonoDevelop. I found the the most recent stable release of Mint 17, using the Cinnamon desktop, worked great, with none of the bloat I found with Ubuntu.

See the following for detailed instructions if you need to set up a Linux VM:

For the purpose of this post, we will assume you are starting with a reasonably fresh VM, and do not already have Mono or MonoDevelop Installed.

As mentioned previously, the links on the MonoDevelop download site don’t get you the most recent Mono release for Ubuntu-based systems. Fortunately, there are some great Personal Package Archives out there which DO.

Install Mono

Your machine may or may not already have Mono installed. Either way, we are going to pull down the most recent, complete version.

Open a terminal in your home folder, and do the following:

Update Everything:
$ sudo apt-get update
Install Mono:
$ sudo apt-get install mono-complete

Once the Mono Installation completes, update again before moving forward:

Update Everything Again:
$ sudo apt-get update

The most recent Mono release is now installed on your machine. Now, let’s get all the goodness of the most recent MonoDevelop release.

Add the Personal Package Archive (PPA) for Latest Stable MonoDevelop Release

To get the most recent stable release of MonoDevelop, we can thank Eberhard Beilharz for making the Stable Version of MonoDevelop PPA at Launchpad.Net.

To get the most recent version of MonoDevelop on our machine, we simply need to add the PPA to our Synaptic Package Manager’s list of sources, and then use synaptic to pull it down.

Add the MonoDevelop PPA to Synaptic:
$ sudo add-apt-repository ppa:ermshiperete/monodevelop

Update to refresh Synaptic:

Update Everything Yet Again:
$ sudo apt-get update

Install MonoDevelop

Now that we have added the PPA, we can use Synaptic just like any other package:

Install MonoDevelop from PPA:
$ sudo apt-get install monodevelop-current

Again, update everything:

Update Everything One More Time:
$ sudo apt-get update

Now, as indicated on the MonoDevelop PPA site, the install we just completed placed a shell script at /opt/monodevelop/bin/monodevelop-launcher.sh

Let’s add an alias for this, so that we don’t have to deal with that big long path every time we want to open MonoDevelop.

If this is a fresh install of Mint 17 on your machine, you will need to add a .bashrc file. If you already have a .bashrc file (or a .bash_profile file – in Mint they are functionally the same), add one:

Add a .bashrc File in your Home Directory:
$ touch .bashrc

Next, add an alias to .bashrc pointing to and executing the shell script:

Add Alias to Execute MonoDevelop-Launcher Script:
$ echo >> .bashrc "alias monodev=Exec=\"sh /opt/monodevelop/bin/monodevelop-launcher.sh\""

Close the terminal, and open a new terminal instance. You should now be able to open MonoDevelop from the terminal by typing, simply “monodev”

With that, we have successfully installed the most recent release of MonoDevelop on our Mint 17 or Ubuntu machine. However, we are likely to find that Nuget, and Nuget package restore, give us difficulties in this out-of-the box scenario.

Making Nuget Package Restore Work in MonoDevelop

Out-of-the-box, Nuget works a little differently in MonoDevelop than we are accustomed to in Visual Studio (this is true of much about MonoDevelop, actually…).

To see what I mean, use your new terminal alias and open MonoDevelop. Then, create a new Console project. Once that’s done, take a moment to get oriented.

We can add Nuget packages by right-clicking on individual projects within the solution in the tree to the left:

Add Nuget Packages in MonoDevelop:

add-nuget-packages

However, if we try to add Nuget packages right now, we get a big FAIL:

Add Nuget Packages Fails in MonoDevelop:

add-packages-fail

WAT?

What’s equally confounding is that, if we were to open and build an existing project which required Nuget Package Restore, the Package Manager would is not always able to connect to Nuget to pull down the packages, and an error would result.

This doesn’t affect all packages, but enough to be annoying. In particular, several NUnit-related packages and a few others, appear to be affected, and your project can’t be properly built.

As it turns out, we are missing some important SSL certificates. The fix is simple, and we can do it from our terminal.

Add Required SSL Certificates for Nuget to Work in MonoDevelop

Since we are using our current terminal instance to run MonoDevelop, we will either need to quit MonoDevelop, or open a new terminal instance, and then execute the following to import a number of important SSL certificates:

Import SSL Certificates from mozroots:
$ mozroots --import --sync

Once we have run this command, we should be able to add Nuget packages at will. Also, Update Packages, and Restore Packages commands from the Solution context menu both should work with no problems.

Additional Resources and Items of Interest

ASP.Net
ASP.NET MVC 5 Identity: Extending and Modifying Roles
ASP.Net
ASP.NET Identity 2.0: Implementing Group-Based Permissions Management
ASP.Net
Configuring Db Connection and Code-First Migration for Identity Accounts in ASP.NET MVC 5 and Visual Studio 2013
  • Bertram Gaubert

    Thanks for this article


  • John Atten

    John AttenJohn Atten

    Author Reply

    I don't disagree about Arch, or one of the more advanced *nix distro's. But for those of us just getting started, Arch may be a bit too much to bite off.

    Also, I suspect those who are proficient with Arch may not be the target of an article like this. :-)

    I suspect most, like me, use Mint/Ubuntu until they are ready to take the *nix training wheels off. I love love love the idea behind Arch, but am not confident enough in my Linux know how to jump into those deep waters yet.


  • nb

    nbnb

    Author Reply

    You may prefer Mint for linux stuff but if you want up to date packages without fuss I'd recommend using Arch

    Here's how I installed the latest stable monodevelop package and mono in Arch:

    sudo pacman -Syu monodevelop

    Done.


  • John Atten

    John AttenJohn Atten

    Author Reply

    @Toni –

    Agreed 100%. Platform wars are stupid. I love my Windows, OSX, and *nix machines. They all have strengths and weaknesses, and folks shortchange themselves when they belittle the other platforms besides their own.

    I've got more in the works, for sure. Thanks for taking the time to comment!


  • Toni Fasth

    Toni FasthToni Fasth

    Author Reply

    Great article for those who are interested in .Net(Mono) development on Linux. For those who think Windows is everything, then maybe it is time to open up your eyes. When developing for Android ( which is based on Linux ) I believe a Linux based platform for development can sometimes be better than using Windows.

    I love Windows, .NET and C# but also love Linux, Java and Android. What Xamarin with help of Mono has done, is that they combined the best of the two worlds. I still prefer VisualStudio over all other IDEs, because none of the IDE competitors can match up with the capabilities of VS when it comes to programming in C#/VB/C++ for .NET.

    But as I stated earlier, this is a great article, and is very helpful to people wanting to develop in Linux using C#.

    I'd love to see similar articles in the future, so keep them coming.