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.
- Set Up Linux Mint in a Virtual Machine Using Virtual Box
- Got Linux?
- Install Mono
- Add the Personal Package Archive (PPA) for Latest Stable MonoDevelop Release
- Install MonoDevelop
- Making Nuget Package Restore Work in MonoDevelop
- Add Required SSL Certificates for Nuget to Work in MonoDevelop
- Additional Resources and Items of Interest
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 188.8.131.52, the most recent package available to Ubuntu, and Ubuntu-based systems from the MonoDevelop site is version 184.108.40.206.
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.
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.
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:
$ sudo apt-get update
$ 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.
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
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.
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:
However, if we try to add Nuget packages right now, we get a big FAIL:
Add Nuget Packages Fails in MonoDevelop:
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.
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.
- Setting Up Linux in a Virtual Machine for Windows Users
- Git: Setting Sublime Text as the Default Editor for Git (Linux Mint/Ubuntu)
- Install Sublime Text 3 (beta) on Linux Mint or Ubuntu
- I am a Programmer, and I can Complicate the #@$% out of a Ball Bearing