I was really curious about doing a little bit of experimenting – working on Visual Studio projects with Mono. What was my idea is the ability to collaborate on the same solution with developers working on completely different platforms with different tools.
I created a WinForms application in Visual Studio 2010. I specified that it is a .NET 3.5 solution (working with the default .NET 4.0 won’t make any sense since it is not supported – it will only open the solution but nothing from that point), but since it is using WinForms 3.5 controls, I was thinking that Mono will probably try to block some things due to an unsupported control version (WinForms 2.0 is listed as the only supported version). The project I created was quite simple – a single form with a couple of standard controls and some LINQ to read a XML file that was bundled with the project. The UI looked like this:
Pretty basic, isn’t it? I didn’t focus much on putting various controls on the form since I was just trying whether Mono will correctly recognize and work the layout and the code behind it. The LINQ code that I was using looked like this:
XDocument doc = XDocument.Load(Application.StartupPath + "\\sample.xml");
IEnumerable<XElement> x = from c in doc.Elements().Descendants() where c.Attribute("id").Value == "1" select c;
foreach (XElement element in x)
With the solution ready, I fired up the virtual machine, loaded Ubuntu and started MonoDevelop. When I navigated to the shared folder, where I copied the Visual Studio solution, MonoDevelop recognized its main file as a known file format (if you take a look at the icon):
So far this was a good sign – this means there is at least something to work with. Once I opened it, there were no error messages or anything – the only problem was with the System.Deployment reference that wasn’t available in Mono (Mono doesn’t support ClickOnce), but that is a known fact so I was well aware that it won’t work.
Now to the most interesting part – the main work form. First of all I must say that there is no visual designer for WinForms applications. For GTK# applications created in MonoDevelop, there will be a somewhat similar toolset as the one for WinForms and a visual designer (although it requires some time to get used to it since its principles are a bit different compared to the Visual Studio WinForms designer), but nothing for WinForms by itself, so in case you are going to work with WinForms applications in MonoDevelop, make sure you know how to work with element layout editing via code.
When I built the project, there were absolutely no errors (but a warning regarding a missing referenced assembly). Now it was time to actually run the project. And it worked!
The layout looked really messy and resembling a Windows 95-ish UI style, but it was loaded. Besides, the control placement was a bit different compared to the one you can see for the same form in Windows.
The LINQ query executed fine and I was able to see the message. Surprisingly, it recognized WinForms controls versioned 3.5. Although I understand that 3.5 controls mostly aren’t much different from 2.0, this was a pleasant surprise.
As a conclusion, I’d like to mention that it is possible to collaborate on .NET projects the way I showed in this article, but after all it will require a bit more work to set the project correctly on Mono (especially due to lack of some tools). Being able to develop cross-platform apps is worth it, though.
In case you want to check whether a project will work on Mono (imported from .NET), I’d highly recommend using MoMA (Mono Migration Analyzer) that can be downloaded here.