Every Flavour Beans

“The time has come…to talk of many [technologies].” –Lewis Carroll(’The Walrus and the Carpenter’)
Development Tools. Web Frameworks. GNU/Linux. Nokia N800. Video Encoding.

June 28, 2006

Writing Your First Program With Mono And MonoDevelop

Filed under: GNU/Linux, Mono — tabrez @ 10:18 pm

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:

C#:
using System;
namespace FirstMono
{
    class Hello
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

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:

Start Monodevelop from the GNOME/KDE menu. 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. 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. 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.

C# Program in MonoDevelop IDE

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


If you want to receive future posts by email, enter your email address here:

Related Posts:

9 Comments »

Hi,
I've gotten everything to work wonderfully with Suse Linux Enterprise Desktop 10 except one thing. Every example I see shows that you can run a .net application directly from the command line. I always have to use mono to execute the binary. If I were to run ./HelloWorld.exe from the command prompt I get "cannot execute binary file" but by running it this way "mono HelloWorld.exe" everything works well. What am I missing? I have also checked to make sure the binary file is marked executable and group, user, and other has permission to execute.

Quote

Comment by Michael Painter — August 10, 2006 @ 10:30 pm

The rules are like this:

Use './HelloWorld.exe' to execute the binary with the .NET framework on Windows(whether it is generated on Windows or GNU/Linux; using .NET or Mono framework). Use 'mono HelloWorld.exe' if it is a file containing compiled IL code(generated using mcs, for eg) and you want to execute it on GNU/Linux or with the Mono(and not .NET) framework on Windows. Use './HelloWorld.exe' in GNU/Linux if it is generated as an X86 executable file (and not as compiled IL code). This executable will not run on a different platform as it contains specific x86 instructions.

Instead of explaining all this in every example on Mono, people generally tend to just say 'execute the Mono app using `./HelloWorld.exe`' and let the user use whatever is appropriate in their case. I have adjusted the post to now use 'mono' to run the application.

Quote

Comment by tabrez — August 11, 2006 @ 10:43 am

Thank you, that undoes all of the confusion!

Quote

Comment by Michael Painter — August 11, 2006 @ 11:54 am

Quick and easy tutorial. Thanks!

Quote

Comment by Marc — October 12, 2006 @ 2:56 am

Hi All,
MonoDevelop is good for Cross-platform .
iam using Monodevelop for my project.but i still i have one dought in Mono Reports.
MonoDevelop Supports ActiveReports and CrystalReport on linux and window?

Regards
m m Kalyan

Quote

Comment by mohan kalyan — November 8, 2006 @ 6:30 pm

You can access the Crystal Reports from C#/Mono on Windows platform. Because CrystalReports.NET makes use of Win32 and COM API, it is not available on gnu/linux platform. You can access Crystal Reports.NET from Mono using the Web Service interface on either platform. ActiveReports is also not available on gnu/linux platform.

Quote

Comment by tabrez — November 13, 2006 @ 1:40 pm

Pranjal Bathia on February 15, 2007 at 6:28 pm said:

mohan kalyan on November 8, 2006 at 6:30 pm said:

Hi All,
MonoDevelop is good for Cross-platform .
iam using Monodevelop for my project.but i still i have one dought in Mono Reports.
MonoDevelop Supports ActiveReports and CrystalReport on linux and window?

Regards
m m Kalyan

We are using monodevelop for our BE project.We are having many doubts about using mono.Would u please help us?

Pranjal Bathia

Quote

Comment by Pranjal Bathia — February 15, 2007 @ 6:28 pm

In Ubuntu 7.10 Gutsy, executing a Mono application can result in: bash: ./Foo.exe: cannot execute binary file
Or if using sh: ./Foo.exe: 1: MZ
But if you install the binfmt-support package, it will work.
openSUSE and SLED probably have a similar package.

Quote

Comment by Mark Strobert — January 10, 2008 @ 3:36 am

Man i was really confused but this short and simple tutorial was excellent.. ..Keep up the great job buddy :-)

Quote

Comment by Rocky — May 28, 2008 @ 9:28 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

Subscribe without commenting


Copyright (c) 2006, 2007 Tabrez Iqbal.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved. A copy of the license is included in the section entitled "GNU Free Documentation License".


Powered by WordPress
This website is hosted by Dreamhost


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser
Mobilytics