Mono

Installing C#/Mono(.NET)/MonoDevelop/XSP in Ubuntu Gutsy Gibbon(7.10)

The reason for not updating the old post that explained how to install C#/Mono/MonoDevelop/XSP packages in Ubuntu Dapper Drake is that the procedure remains pretty much the same for Ubuntu Feisty Fawn as well as the recently released Ubuntu Gutsy Gibbon distributions(but now you get the newer versions of those packages installed, of course). You can just go through that longer post and probably make one or two changes here and there to get everything running under Feisty/Gutsy too.

Do note that Ubuntu Gutsy Gibbon supports installing the more recent stable versions of Mono(1.2.4) and MonoDevelop(1.4) right from its package manager than any other distribution(AFAIK). Mono 1.2.5 is released but it is not available even in Gutsy. All other distribution either install the older versions of Mono and MonoDevelop or make you compile these packages from the sources(which is a good idea even on Gutsy if you want Mono 1.2.5 or some bleeding-edge version of MonoDevelop).

Below is a command running which will get most of the packages related to Mono and MonoDevelop installed on your Ubuntu Gutsy Gibbon(7.10) operating system. The only changes you can notice here are the missing mono-gac package(as it comes installed by default in Gutsy) and the addition of monodevelop-query and libnunit-doc packages. Drop the packages that you don’t want from the command line, and remember that dependencies will be automatically pulled by apt if you accidentally drop any needed packages, so don’t worry too much about it.

sh# sudo aptitude install mono mono-gmcs mono-utils monodevelop monodoc mono-xsp monodoc-http monodoc-ipod-manual monodoc-njb-manual monodoc-nunit-manual monodoc-gtk2.0-manual monodoc-gecko2.0-manual monodoc-ipod-manual monodoc-njb-manual monodoc-nunit-manual monodoc-gecko2.0-manual mono-xsp2 monodevelop-java libnunit-doc monodevelop-nunit monodevelop-versioncontrol monodevelop-query

A lot has changed in the Mono world in the past year but I will leave it up to you to explore the changes according to what version you are interested in. Here are some links to get you started:

What’s new in MonoDevelop 0.14 (stable version available for Gutsy)
What’s new in MonoDevelop 0.15 (stable version but not available for Gutsy, need to compile from sources)
What’s new in MonoDevelop 1.0 Beta 1 (0.16) (unstable version, need to compile from sources)
What’s new in Mono 2.1.4 (stable version available for Gutsy)
What’s new in Mono 2.1.5 (stable version but not available for Gutsy, need to compile from sources)

Keep track of Mono development(RSS)

Create ASP.NET 1.0 & 2.0 Applications On GNU/Linux and Windows Using Mono XSP

This post assumes that Mono is installed on your system. The following links should help if it is not installed.

Installing Mono on Gentoo and Ubuntu 5.10
Installing Mono and XSP on Ubuntu 6.06
Installing Mono and XSP on Fedora

Installing Mono XSP on Gentoo

#emerge xsp xsp2

Installing Mono XSP on Debian/(K)Ubuntu

#sudo apt-get install xsp xsp2

Installing Complete Mono Environment(Mono, GTK#, XSP) on MS Windows

  1. Download the Mono installation file for MS Windows from the Mono website.
  2. Run the installer and follow the installation wizard.

Go to the Mono menu in the Start menu(Start->All Programs->Mono[version]) to access all the applications installed as part of Mono.

Your First ASP.NET 1.0 Application Using Mono XSP

  1. First create a directory to store the ASP.NET files and change to that directory. You can create the directory in your home directory.
    sh# mkdir aspnet && cd aspnet
  2. Create a sample ASP.NET page. Copy and paste the following code in two separate files(hello.aspx and hello.aspx.cs).
    hello.aspx

    [html]
    <%@ Page language="c#" src="hello.aspx.cs"
    Inherits="HelloApp.HelloPage" AutoEventWireup="true" %>



    Welcome to my page!

    Enter your name:

    Hello, World!



    [/html]

    hello.aspx.cs

    [csharp]
    using System;
    using System.Web.UI.WebControls;

    namespace HelloApp
    {
    public class HelloPage : System.Web.UI.Page
    {
    protected Label message;
    protected Button greet;
    protected TextBox name;

    public void OnGreetClick(Object sender, EventArgs e)
    {
    message.Text = “Hello, ” + name.Text;
    }
    }
    }
    [/csharp]

  3. From the same directory(‘aspnet’), start the XSP server:
    sh# xsp

    (you can press ENTER to terminate the XSP server process)

  4. Open a web browser, type the url http://localhost:8080/hello.aspx and press ENTER. You should see a web page with a text box and a message. Enter a name in the text box and click the “Greet” button to see the personalised greeting displayed.

On MS Windows, go to the Mono menu in the Start menu(Start->All Programs->Mono[version]), select “Mono[version] Command Prompt” menu item. Create a directory(say ‘c:\programs\aspnet’), change to that directory and copy the above two files in that directory. From the same directory, run ‘xsp’ commad to start the XSP webserver. Open a web browser and access the url http://localhost:8080/hello.aspx.

Your First ASP.NET 2.0 Application Using Mono XSP

To develop ASP.NET 2.0 applications using Mono XSP server, start ‘xsp2′ webserver instead of ‘xsp’. Create a test ASP.NET 2.0 page(say ‘hello2.aspx’) and copy it in a folder. Run the following command from the same folder:

sh# xsp2

Go to http://localhost:8080/hello2.aspx to test the ASP.NET 2.0 page.

C# Program in MonoDevelop IDE

Writing Your First Program With Mono And MonoDevelop

Installing Mono And MonoDevelop on Gentoo and Debian/Ubuntu(5.10)
Installing Mono And MonoDevelop K/Ubuntu(6.06)

Mono applications can be developed using any text editor and the mono compiler(mcs). Type the following program in your favourite editor:
[csharp]
using System;
namespace FirstMono
{
class Hello
{
public static void Main(string[] args)
{
Console.WriteLine(“Hello World!”);
}
}
}
[/csharp]

C# Program in MonoDevelop IDE

Now go to a shell prompt and compile and run the program:

sh# mcs Hello.cs
sh# mono Hello.exe

You can copy the same Hello.exe file to a Windows machine and execute it there; you get the same output.

To create a C# application using the MonoDevelop development environment, follow these simple steps:

  1. Start Monodevelop from the GNOME/KDE menu.
  2. Select ‘File->New Project’ or press Ctrl-Shift-N to create a new Project/Solution. Select “C#” in the left pane and “Console Project” in the right pane of the dialog box.
  3. Type ‘FirstMono’ as the project name(in Location->Name field) and press the “New” button. You will see a sample C# file created in the open window(sample code is not created if “Blank Project” is selected in the “New Solution” Dialog box). Modify the string passed to the WriteLine() method if you wish.
  4. Select “Run->Build Solution” to build the project. Run the project using “Run->Run”(or press “F8″). The output is displayed in the Application Output window at the bottom.
  5. C# Program in MonoDevelop IDE

    Most of the frequently used operations(like “Build Solution”, “Run” etc) can be invoked from the toolbar buttons too.

monodoc-menurs.png

Installing C#, Mono(.NET) & MonoDevelop in Ubuntu Dapper Drake 6.06

Installing the complete Mono environment, including the runtime, the compiler and the development environment(MonoDevelop), is no more difficult in Ubuntu 6.06 than it was in Ubuntu 5.10.(The procedure for installing Mono for Kubuntu 6.06 is also similar, but GTK and related packages are needed to install the MonoDevelop IDE, which will be a big download if GNOME is not already installed.) After adding Multiverse and the Universe repositories to the Ubuntu source list, run the following commands in a shell(or use Synaptic/Adept Package Managers):

sh# sudo apt-get install mono mono-gmcs mono-gac mono-utils monodevelop

Except ‘mono’ all other packages are optional. mono-gmcs is C# 2.0 compiler(By default, mono-mcs C# 1.0 compiler is installed). MonoDevelop is a GUI development environment for Mono development(primarily). The above command will also install the Mono documentation manual(monodoc-manual). For a standalone Mono documentation browser, install monodoc-browser. If you prefer to read the documentation in a web browser, then install monodoc-http(which needs mono-xsp):

sh# sudo apt-get install monodoc mono-xsp monodoc-http

In the above command, monodoc package automatically installs monodoc-browser. Now you can view Mono documentation either in the stand-alone browser or in the web browser, by selecting the appropriate menu item from the GNOME/KDE menu:
MonoDevelop Menu Items
Click the Monodoc(Documentation Browser) to browse through various help topics on Mono development:
Mono Documentation Browser
You can install many other Mono based development manuals too, like Mono iPod manual, Mono njb manual(njb is a library used to talk to Creative MP3 Players etc), Mono NUnit manual etc.

sh# sudo apt-get install monodoc-ipod-manual monodoc-njb-manual monodoc-nunit-manual monodoc-gtk-manual monodoc-gtk2.0-manual monodoc-gecko2.0-manual

Search for more documentation packages using ‘sudo apt-cache search mono | grep manual’ command or using Synaptic/Adept Package Manager.

The following related tools are also available in the repositories:
monodevelop-java: To develop Java applications in MonoDevelop. Needs Java to be installed.
monodevelop-nunit: NUnit support in MonoDevelop. Strongly recommended.
monodevelop-versioncontrol: Only subversion is supported(no CVS).

sh# sudo apt-get install monodevelop-java monodevelop-nunit monodevelop-versioncontrol

mono-xsp is a standalone webserver that can be used to run ASP.NET 1.0 & 1.1 applications. mono-xsp2 runs ASP.NET 2.0 applications.

sh# sudo apt-get install mono-xsp mono-xsp2

If you would rather host the ASP.NET applications through Apache webserver, then you need mono-apache-server package. Note:

mono-apache-server + libapache-mod-mono –> Apache 1.3
mono-apache-server + libapache2-mod-mono –> Apache 2.0

Similarly, mono-apache-server2 is for ASP.NET 2.0.

sh# sudo apt-get install mono-apache-server2 libapache2-mod-mono

This will automatically select the mono-apache-server2 package. Remember that this will also install Apache server and related packages if they are not already installed. The next post will be about creating a sample Mono program using the MonoDevelop development environment.

C# & MonoDevelop (.NET) on Gentoo and Ubuntu

.NET developers looking for a similar development framework on the GNU/Linux operating system should check out the Mono project. It’s fairly simple to install Mono on most of the GNU/Linux platforms and to start developing applications using the C# language. But beginner programmers would love to have an easy to use IDE which could integrate all the tools required for C# based development in one place. One such tool is MonoDevelop which is fast developing into a useful product. Installing it on rpm based distribution was not a satisfactory experience for me however. But I knew it should be easy to install it on Ubuntu and Gentoo operating systems. if you have included Mutliverse and Universe repositories in the apt source list, then MonoDevelop is just one 'apt-get install' away on Ubuntu.

sh# sudo apt-get install monodevelop

It required only a bit more effort on a Gentoo system, so I am documenting it here. Most of the packages required to get MonoDevelop working on a Gentoo system are in the masked state. Put the following lines in the /etc/portage/package.keywords file(create it if it already doesn't exist):

>=dev-dotnet/gtkhtml-sharp-2.4.0 ~x86
>=dev-dotnet/glade-sharp-2.4.0 ~x86
>=dev-dotnet/gconf-sharp-2.4.0 ~x86
>=dev-dotnet/art-sharp-2.4.0 ~x86
>=dev-dotnet/gnome-sharp-2.4.0 ~x86
>=dev-dotnet/vte-sharp-2.4.0 ~x86
>=dev-dotnet/gnomevfs-sharp-2.4.0 ~x86
dev-dotnet/gtksourceview-sharp ~x86
dev-dotnet/gecko-sharp ~x86
dev-dotnet/libgdiplus ~x86
dev-util/monodevelop ~x86
dev-lang/mono ~x86

you can drop ">=" in front of some of the lines above by dropping the version numbers in the same lines.
eg: dev-dotnet/gtkhtml-sharp ~x86

Now run the following command to get everything installed:

sh# emerge monodevelop

Similarly 'emerge mono' will get only the mono environment, and all the development can be carried out using your favourite editor and the command shell.

If you get any problems, first try 'emerge sync' to get everything synchronised, and then re-run 'emerge monodevelop'. If you still get any errors, see if still there are any dependency problems left that are in the masked state. if so, add them too to the '/etc/portage/package.keywords' file and repeat the process.
Let me know how this works out for you as I haven't found much information regarding this on the internet.