I make tools to help people create wonderful things.


MonoDevelop Tips: Custom XML Schemas

MonoDevelop's XML autocompletion is driven by XML schemas, although there is a fallback that will use existing nodes in the file to provide a very basic form of completion. MonoDevelop keeps a list of known schemas, and when trying to provide completion for a given namespace, it looks in that list to find one that matches the namespace. There are built-in schemas for several namespaces, but it's possible to add your own in Preferences->Other->XML Schemas. Registered schemas must have a unique namespace, since that's how they're identified.

The custom XML schemas panel

In the option panel there is also a list of file associations. If you add a file extension to this list, it will be treated as XML, so it will get syntax highlighting, code folding, code completion. and so on. You can also specify the default schema for the file, using one of the registered schemas. This will be used as the schema for the root element, even if it's not explicitly specified in the file.

MonoDevelop Tips: Author Information

There are many convenient things MonoDevelop can do, but for some it needs to know a bit about you, such as your name, your email address, and who owns the copyright on your work. This is used for adding standard file headers, committing to a VCS repository, creating AssemblyInfo.cs files, and so on. You can provide this information in the Author Information panel in Preferences.

The author information panel

If there is a solution for which you wish to use different information, you can override the author information for that solution in the Solution Options. This is stored in the solution's user preferences (the *.userprefs file) so it won't be shared with other users.

MonoDevelop Tips: Inline Errors

In MonoDevelop 2.4, we introduced inline error markers, similar to Xcode. When you build, errors and warnings are shown inline in the code as message bubbles, though of course they also remain available as a list in the Error List pad.

An inline error message bubble

We do our best to make sure the message bubbles don't become too intrusive, but remain usable. They are normally shown on the end of the line that they affect, but if they are too long, they will wrap onto a new line. If they are really long, they ellipsize, but the full error remains available on a tooltip. If there are multiple errors or warnings on one line, they collapse down to a single line with an indicator indicating how many there are. Clicking on this indicator or moving the caret into the line causes the bubble to expand over the lines below and show all the messages, and clicking on the indicator again or moving the caret out of the line causes the bubble to collapse.

A collapsible inline error message bubble

Editing a line with a message bubble causes the bubble to dim slightly, to indicate that it's probably no longer valid.

By default, message bubbles are shown for both warnings and errors, and MonoDevelop takes you to the first error immediately after the build. These behaviours are configurable in Preferences->Build, where you can configure what happens after the build: whether to jump to errors and warnings, or just errors, or not at all; whether to show the error pad automatically; and whether to show message bubbles for errors, for errors and warnings, or not at all.

The inline error options

There are several commands for working with message bubbles, accessible from the View->Message Bubbles menu. The Hide/Show Message Bubble command hides or shows all the message bubbles, and the Toggle Message Bubble command hides or shows just the message bubbles on the current line. The latter command is also accessible via the context menu in the text editor margin. When bubbles are hidden, the error marker in the margin will remain there until the next build.

MonoDevelop Tips: Duplicate a Line

When there is no selection in the MonoDevelop text editor, the copy and cut commands act on the current line. This makes it easy to move a line (Control-X, move to line below target location, Control-V) or duplicate a line (Control-C, Control-V).

MonoDevelop Tips: Build Actions

Files in a MonoDevelop (or Visual Studio) project have a build action which controls what happens to the file during a build. Here are some of the common build actions for C# projects:

The file will be passed to the C# compiler as a source file.
The file will be passed to the C# compiler as a resource to be embedded in the assembly. For historical reasons, it's displayed as "Embed as resource".
The file is not part of the build in any way, it's simply included in the project for easy access from the IDE.
For ASP.NET projects, these files will included as part of the site when it's deployed. For MonoTouch and MonoMac projects, they'll be included in the app bundle.
In Silverlight/Moonlight projects, this is used for xaml files to be included in the app. In MonoTouch and MonoMac, it's used for xib files.

You can also define arbitrary build actions, and if your project uses the MSBuild build engine, you can write custom tasks to process files with particular build actions.

There are various ways to set files' build actions. When files are first added to the project from templates, they will have an appropriate build action set by the template. When files are added from the Add Files dialog, they will have the default build action for that file type, unless you explicitly override it using the combobox in the dialog.

Overriding the default build action when adding files

For files that are already in the project, you can change the build action by selecting the file in the solution pad, then using the dropdown in the property pad.

Changing the build action using the property pad

Common build actions can be set using the solution pad's context menu, which has the advantage that it supports multi-selection, so you can change many files at once.

Changing the build action using the solution pad context menu

MonoDevelop Tips: Pinned Search Results

Some kinds of pads in MonoDevelop are transient. They cannot be accessed directly from a menu, but instead appear when needed to show the results of some operation, such as Find in Files, or Find References. Once closed, they can only be recovered by re-running the operation.

When another operation of the same kind runs again, it re-uses any existing pad of that kind, so they don't proliferate wildly. However, you can "pin" the pad by using the pin button in the pad, which means that it will not be re-used this way. Instead, the next operation will create a new pad. You can pin several pads, to save several sets of results, and further new pads will be created as necessary. When you are done, close or unpin the pad.

The following image shows a pinned pad. The pin button is at the bottom on the right side of the pad. Note that some MonoDevelop builds have a bug that causes the icon not to appear, but the button is still present and usable — it highlights when the mouse move over it, and shows a depressed state when enabled.

A pinned Search Results pad

MonoDevelop Tips: Show All Files

The MonoDevelop Solution Pad shows projects and folders that correspond to real folders on disk, but by default it only shows files and folders within them that have been included in the project. This behaviour can be changed using the Display Options->Show All Files toggle option in the Solution Pad context menu. The option is contextual — it applies only to the item on which it is toggled, and recursively applies to all its children. To have it apply to the whole Solution Pad, toggle it on the root solution or workspace.

When Show All Files is enabled, files that are not included in the project will be shown in the folder hierarchy, but with semi-transparent icons to indicate their status. They can be edited and moved and so on, though they will not be included in the code completion system. Perhaps the most useful thing that this option enables is the Include in project context menu command on non-included files, which can be used to include them in the project quickly and easily.

MonoDevelop Tips: Code Generation Window

The Code Generation window can be used to automatically generate code for various patterns, based on existing code. It can be triggered from the context menu, or from the Edit->Show Code Generation Window menu. On Windows and Linux the keyboard shortcut is Alt-Insert and on Mac there's currently no keybinding (if you'd like to suggest one please use the MonoDevelop mailing list).

The code generation window is shown at the caret location, and its contents are context-dependent. For example, within a method it can generate things like null checks for the method's arguments, and in a class body it can generate things like a constructor with parameters that are assigned to properties and fields in the class.

Highlight usages

Navigate up and down in the window using the arrow keys to select the code generator you wish to use, then move to the item list using the enter or tab key. Here you can navigate up and down using the arrow keys and toggle items on and off using the space key. The mouse can be used too, but the keyboard is much faster. if you change you mind about which generator to use, shift-tab will move the focus back up to the list of generators. Finally, press the enter key to generate the code for the items you selected.

Here is the constructor code generated after selecting all three properties in the dialog shown above:.


MonoDevelop Tips: Hidden Editor Commands

The MonoDevelop text editor has many commands are not immediately obvious. Some are accessible from the Edit and Edit->Format menus, and some have default keybindings, but many can only be used if you manually add keybindings for them. Some even have keybindings that are hardcoded into the text editor, and will be available unless you override it by assigning that some keybinding to some other command.

Here is a selection of some that may be useful:

Join Lines
Joins the current line with the next line, i.e. removes the next line and appends it to the current line, separated by a space. If multiple lines are selected, it will join them all into one line.
Transpose characters
Swaps the characters on either side of the caret (Control-T on Mac)
Delete to end of line
Deletes from the caret to the end of the current line (Control-K on Mac)
Find caret
Triggers an animation showing where the caret is (Command-| on Mac)
Go to matching brace
Moves the caret to the counterpart of the adjacent brace or bracket
Insert line break after caret
Moves the text after the caret onto a new line without moving the caret (Control-Enter on all platforms, and also Control-O on Mac)
Move caret to EOL and insert new line
Inserts a new line below the current line and moves the caret to it (Shift-Enter on all platforms
Recenter editor
Moves the scrollbars so that the caret is centered in the editor (Control-L on Mac)

MonoDevelop Tips: Next/Previous Usage

After the caret has been in an identifier in a C# file for a few seconds, then all the usages of that identifier in the current file are highlighted. This provides a nice visual cue for finding related code and following code flow.

Highlight usages

There are also commands for quickly moving between these usages. On Windows and Linux they're bound to Control-Shift-Up and Control-Shift-Down, and on Mac they're Command-Shift-Up and Command-Shift-Down.


Subscribe to Journal