Introduction In the previous article we looked at the options for developing cross-platform applications in C# programming. The technology that makes this possible is Mono from Novell. In this article we'll take an existing Windows C# application and run it on both Mac OS X and Linux.
Before we dive into the details it's important to take a quick look at what Mono is and where it came from to help you understand what's happening behind the scenes. The Mono project has been around for almost nine years and started out as an effort to implement an open-source version of the ECMA-standard (ECMA-334) C# programming language and the companion Common Language Infrastructure or CLI (defined in ECMA-335). These standards correspond with Microsoft's products commonly known as the.NET framework platform. Programs written with Mono run on different platforms through the use of native run-times.
Dictionary.com is the world’s leading online source for English definitions, synonyms, word origins and etymologies, audio pronunciations, example sentences, slang phrases, idioms, word games, legal and medical terms, Word of the Day and more. For over 20 years, Dictionary.com has been helping millions of people improve their use of the English language with its free digital services.
If fact, you can run the exact same.EXE file on any supported platform with the Mono runtime installed. Version 2.0 of the Mono runtime was the first release to provide robust support for native Windows Forms applications. That basically means that Novell implemented all of the System.Windows.Forms namespace. Under the cover, Mono uses the System.Drawing library along with drivers for X11, Win32 and OS X to do the heavy lifting.
While Windows Forms applications will run on any supported platform, you'll still have to use Microsoft Visual Studio for the actual design and coding if you want to use a visual designer. We'll discuss the Mono Visual Studio add-in a little later. Porting Considerations While Mono makes it possible to run Windows Forms-based apps on virtually any OS, it doesn't mean they will look great on another platform. In many cases the look and feel will be adequate, but there may be some cases where the differences are significant. The on their website that walks you through the process of porting an application using the to determine potential issues. To test out MoMA we downloaded a number of Windows Forms samples from the. The illustrates an issue that tends to pop up between platforms.
When you run the MoMA tool against the RegexTest.exe file, it gives the following warning: Form.setAutoScaleBaseSize (Size) Setting this is probably unintentional and can cause Forms to be improperly sized. See for details. The result when you run the application on Linux is a chopped off window that doesn't fully show the buttons at the bottom of the form.
Figure 1 shows what it looks like on Windows, and figure 2 shows the same application running on Linux. Figure 1 RegexTest application running on Windows Figure 2 RegexTest application on Linux The fix is a simple one in this case. All of the visual components of this application are built in code, and the line that sets the size looks like this: this.ClientSize = new System.Drawing.Size(536, 503); Changing it to the following fixes the problem: this.ClientSize = new System.Drawing.Size(536, 536); Figure 3 Updated RegexTest app running on Linux. Things to Watch For One of the things that can cause problems when porting apps between operating systems stems from subtle differences like file naming conventions. Windows filenames are case insensitive while both Mac OS X and Linux are case sensitive.
This can lead to issues if you have filenames for things like resources or images referenced either in code or in a configuration file that aren't consistent. You must also deal with the different usage of the ' ' versus the '/' in path names. Mono does offer a feature they call IOMap to specifically help with the path issue. If you happen to be a Ubuntu, user you'll find the latest version of Mono available through the normal update channels is 2.4.4.
While that shouldn't be a big issue, you could run into some problems if you're using any of the Language Integrated Query (LINQ) features. The latest version of Mono also begins to implement some of the C# 4.0 features along with ParallelFX, although you'll have to wait for at least 2.8 to get started with those. One option for getting Mono 2.6 up and running on Ubuntu 10.4 is to build it from source. There are on how to do it, but the process is not for a beginner. A quick Google search turned up about installing Mono 2.6.x in parallel on Ubuntu 9.10. You'll need to have subversion installed along with libtool to get the script to work properly.
Wrapping Up One of the things we didn't cover in these two articles is the ability to write C# code using Mono for Apple's iPhone, iPod Touch and iPad. While you won't be able to take your Windows Forms apps to those platforms, you will be able to code in C#. It requires you to do all the coding on a Mac and use the Apple SDK. Building the actual interface can be done either programmatically or by using Apple's Interface Builder. Future versions of this same tool are planned for Google's Android platform as well. Novell's Mono product is essentially the only game in town if you want to take an existing Windows Forms app and run it natively on Linux or Mac. It's also the primary force behind a number of popular open source apps like the Banshee media player and F-Spot photo manager.
Mono is definitely worth a look if you have a need for cross-platform apps.
Hi Sean, Thank you for your post. To run.NET application, we should install.NET Framework on the target machine to support it. As far as I know,.NET Framework can only be installed on computers running a Microsoft Windows operating system. Please see: As Hans mentioned, the third-party Project has been developing an open source implementation of the ECMA standards that are part of.NET Framework, as well as most of the other non-ECMA standardized libraries in Microsoft's.NET. The Mono implementation is meant to run on Linux, Solaris, Mac OS X, BSD, HP-UX, and Windows platforms.
If you have any concern, please feel free to let me know. Best regards, Yichun Chen (This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.) Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback, please tell us. Hi Sean, Thank you for your post. To run.NET application, we should install.NET Framework on the target machine to support it. As far as I know,.NET Framework can only be installed on computers running a Microsoft Windows operating system. Please see: As Hans mentioned, the third-party Project has been developing an open source implementation of the ECMA standards that are part of.NET Framework, as well as most of the other non-ECMA standardized libraries in Microsoft's.NET. The Mono implementation is meant to run on Linux, Solaris, Mac OS X, BSD, HP-UX, and Windows platforms. If you have any concern, please feel free to let me know.
Best regards, Yichun Chen (This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.) Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have any feedback, please tell us.