Creating A Simple Solution

From $1
    Table of contents

    Introduction

    The purpose of this tutorial is to outline the basic process for creating an application with MonoDevelop, and also provide some tips for getting started. Our example for this tutorial will be a simple console application which references a separate library.

    Terminology

    • Solution: a group of MonoDevelop Projects. This information is stored in an xml formatted file with the extension '.mds' in your solution directory. Note: a Solution can contain Solutions.
    • Project: a buildable target. Either a library or an executable. It is comprised of source code files, references to libraries, and resource files (such as images). This information is stored in an xml formatted file with the extension '.mdp' in your solution directory.

    Step 1: Create the Solution

    From the File menu, select "New Project", this will open up the "New Project" window. Select "C#" from the language list and "Console Project" from the templates. Give your application a name as so:

    New_Solution_Window.png

    When you are finished, click the "New" button. This creates a new directory for your solution in the Projects directory of your home directory. The "Console Project" template provides an already buildable application. You can test by selecting "Run" from the "Run" menu. This will build the application, and provide the output in an "Application Output" tab.

    Step 2: Create A Library Project

    For our sample application, we do not want to include all of our functionality in the executable, so we want to create a library. To do this, right click on the Solution icon in the Solution Pad. Select "Add->Add New Project". From the "New Solution" window, select "C#" as the language and "Library" as the template. Name it "MyLibrary" and click "New". This will create a new project within your solution.

    Now your solution has a new library with one class "MyClass" which initially does absolutely nothing.

    Step 3: Using the new library

    Setting the Startup Project

    Now we have two projects in our solution: an executable and a library. A solution can have multiple executable projects. You can specify the startup project (i.e. the project which is built and run when using the "Run" command) by right clicking on the Solution icon in the Solution pad and choosing "Options", then Common->Startup Properties. From there you can select single or multiple projects:

    Solution_options.png

    A solution with multiple projects will build and execute all of them in the order you specify. However, we want to set our startup application to "MyApplication" because this is the executable that we want to run.

    Referencing our Library

    If we are going to be able to use our new library, MonoDevelop needs to know this. We do this by adding a reference to it. From the Solution Pad, expand the node for our project "MyApplication", this will reveal a References node among others. Right click this and select "Edit References". This will bring up the References dialog. Select the "Project" tab. Our library should appear in the list, and we can check it as so:

    Edit_references_project.png

    Click "Ok". Now we have all the classes in our library "MyLibrary" available to our application (exactly one). Let's test this by creating an instance of the class "MyClass". Add the following to MyApplication->Main.cs:

    // project created on 01/19/2006 at 14:19
    using System;
    using MyLibrary;
    
    class MainClass
    {
    	public static void Main(string[] args)
    	{
    		MyClass test = new MyClass (); 
    
    		Console.WriteLine("Hello {0}", test); 
    	}
    }
    

    Our Library in Action

    Finally, we can build and run our application, which should produce the following output:

    Hello MyLibrary.MyClass
    

    Conclusions

    While this output is not particularly impressive, hopefully this tutorial has helped you to grasp the basics of MonoDevelop, and perhaps given you some starting points on how to set up and begin developing your applications.

    Others Tips

    Building from the Command Line

    As of MonoDevelop version 0.9, it is possible to build your solution from the command line. Using the above example, we could do:

    mdtool build --f --buildfile:MyApplication/MyApplication.mds
    

    Which will produce:

    MyApplication/MyApplication.mds
    MonoDevelop Build Tool
    Loading combine: /home/scottell/Projects/MyApplication/MyApplication.mds
       Loading project: /home/scottell/Projects/MyApplication/MyApplication.mdp
       Loading project: /home/scottell/Projects/MyLibrary/MyLibrary.mdp
    Building Solution MyApplication
       Building Project: MyLibrary Configuration: Debug
          Performing main compilation...
          Build complete -- 0 errors, 0 warnings
       Building Project: MyApplication Configuration: Debug
          Performing main compilation...
          Build complete -- 0 errors, 0 warnings
    
    Tag page
    • No tags

    Files (3)

    FileSizeDateAttached by 
     Edit_references_project.png
    No description
    13.14 kB09:09, 15 Feb 2012LluisActions
     New_Solution_Window.png
    No description
    41.38 kB09:08, 15 Feb 2012LluisActions
     Solution_options.png
    No description
    28.12 kB09:08, 15 Feb 2012LluisActions
    Viewing 7 of 7 comments: view all
    Great !
    I tryed so hard and couldnt even Stop my App without YOUR helping tutorial !!
    thanks RUDI
    Posted 21:53, 24 Oct 2009
    Thank.This's useful.
    Posted 17:05, 22 Dec 2009
    This is not correct in my version (2.2 on Mac). The File menu contains New->Solution (not New->Project).
    Posted 21:54, 20 Jan 2010
    Sorry, I don't speak english very well, but it's great and very interest. (espero haberolo dicho bien)
    Posted 07:17, 1 Mar 2010
    Great first step! I'll definitely read the next sections.
    Posted 18:06, 26 Mar 2010
    Great start but seems to be the finish, too. Anyone know where we can get continuing instructions? I've got a web app created that has a button and nothing else and I don't know what next to do...
    This IDE doesn't seem to have a sidebar with details of the object (the button) and what events and properties it has... so how to add my code to the button so's it will do what I want it to do?
    anyone knows and doesn't want to write it here (because this isn't a proper forum, looks like, I wouldn't get any notification you'd written) you could email me at abrogard@yahoo.com
    cheers. :)
    Posted 08:03, 12 May 2010
    The instructions are sometimes difficult to follow because they do not correspond with screens in v2.4.1 (Fedora 14) or 2.8.1 (Fedora 16). Do not know which version these screen examples come from. Using clear terminology and defining terms or including a layout diagram might assist with the terms uncommon to newcomers. Assuming some terms and titles are versioning issues and that posting images for each version might be too cumbersome, it could help if the text identified certain version naming differences in the images.

    Step 1 works, but "New" button is named "Forward" and instructions do not mention the "Project Features" dialog that pops up. Did not check any of those features. Would be nice to know what those features are for. Clicked "OK" and created app. App runs.

    Step 2 unclear. On the left is a sidebar with the title "Solution." Never heard it called a pad before, which caused me some fumbling around for a while. (Seems to me a pad is writeable while a sidebar is a rectangular area to one side of the main text containing extra information. These "pads" are not writeable by the user. Therefore, these are sidebars, but app-specific terminology could call them pads if that definition were given in the text.) The sidebar title itself is not clickable. In the sidebar is a tree structure. First entry in the sidebar tree is named "Solution" followed by the app name and an entry count of the branches descending from the tree holding my app. Each entry in the tree is right-clickable to show a menu. Different entries in the tree have similar menus. Only the first entry ("Solutions" with app name and count) has the documented "Add->Add New Project" options. Clicking it brings up a dialog named "New Project" instead of "New Solution." Clicking "Forward" again brings up the unmentioned "Project Features" dialog. Did not select any and clicked the "OK" button.

    Step 3 in the subheading "Setting the Startup Project" refers to "Common->Startup Properties," but the "Solution Options" has a "Run->Startup Project" entry. In the subheading "Referencing Our Library" is an image of the "Edit References" dialog. The first tab is named "Packages" instead of "Global Assembly Cache." As a convenience, highlighting the new code lines in the example would be helpful.
    Posted 20:28, 8 Mar 2012
    Viewing 7 of 7 comments: view all
    You must login to post a comment.
    Page last modified 09:10, 15 Feb 2012 by Lluis