Write standards-compliant C# programs in Linux with DotGNU
Write C# programs in Linux with the free and vendor-neutral DotGNU.
Like many, I grew up programming in C and C++ before moving into LAMP-land and Python, Perl, and PHP. But like that first car, first date, and first paycheck, everyone has a special memory of the first time they compiled gibberish into executable machine code.
Thanks to GCC, open source developers have never had any issues writing C or C++ code on a Linux platform. However, when Microsoft announced their .NET initiative and the intention to focus their efforts around C#, few people expected Microsoft to release a Linux client for their "platform-independent" development tool.
Fortunately, .NET's Common Language Infrastructure (CLI) and the C# programming language are codified as ECMA (a non-profit standards body) and ISO international standards, which creates the possibility for independent implementations. The DotGNU project was started with huge fanfare to bring standards-compliant C# to Linux. Over the years, DotGNU has received less attention than the other .NET for Linux: the Novell-sponsored Mono project. Nevertheless, the project is still chugging along, and it is even finding some use in commercial applications.
Although DotGNU has lost some of its steam in recent years, it is still in active development. Certainly one cannot compare the pace of development with that of Mono – or even with its own initial activity – but that's mainly because, at DotGNU, the emphasis is on standards compliance and staying free of license restrictions, rather than on being compatible with the latest from the Microsoft camp. As DotGNU developer Klaus Treichel points out, it is unfair to compare DotGNU with Mono because Mono has full-time developers paid by a large company. DotGNU has always been a voluntary project supported with donations. One such donation was from Trumpf Group, which has a pulsed laser cutting tool that uses DotGNU. The touch screen user interface of the laser tool was built through the use of DotGNU.
Although some parts of the Mono environment (including the C# compiler) are released under the GPL, other parts are subject to license and patent concerns that reflect the complex business relationships between Novell and Microsoft. Fortunately for us, then, the DotGNU project offers a vendor-independent alternative for open source programmers who want to try their luck with C# and .NET.
Breaking Down DotGNU
DotGNU is more than just a C# compiler, but I'll start off with that. Portable.Net is the free implementation of .NET, and it contains a run-time engine, a C# compiler, and a host of other tools that make Portable.Net easy to port to other platforms. All these components are written in C. The aim of the project is to make the development of .NET apps easy on non-Microsoft platforms.
In the early days of development, the C# system library was split from the main Portable.Net distribution. The libraries are now available as part of the pnetlib package. Another important component is treecc, an aspect-oriented programming tool that assists in development with the DotGNU C# compiler.
For writing web services, DotGNU relies on the DotGNU Execution Environment, or DGEE, and phpGroupWare. DGEE is a web-service server that can accept and process XML-RPC requests from web services, and it can generate browsable documentation for these services in HTML or XML. phpGroupWare is a groupware suite that also provides a host of web-service components.
The DotGNU C# compiler also compiles programs written in C, thanks to the libc implementation of the C compiler, pnetC. Because DotGNU's objective is to follow the standards, rather than follow Microsoft, the implementation lacks a few assemblies. To help developers use the missing bits, the DotGNU folks distribute some of the libraries from the Mono project. This distribution of the Mono libraries is achieved via the build scripts in the ml-pnet package.
Why Program with DotGNU?
One of the main reasons for writing C# code in DotGNU is that it is compatible with the EMCA standards for C# and the CLI. Furthermore, DotGNU also is compatible with Microsoft's own CLI implementation of the .NET framework.
Thanks to the modular design of Portable.Net, the DotGNU C# compiler can run on multiple platforms. Portable.Net's run-time engine and the C# class library have extensive support for embedded system profiles and can be built with different ECMA profiles. Each profile enables or disables features in the system. As a testament to its portability, one of the founding developers, Gopal Vijayaraghavan, was able to get Portable.Net running on the Indian hand-held computer, the Encore Simputer, during the three days of FOSS.IN in Bangalore.
Programmers also will appreciate the self-contained nature of DotGNU and that it doesn't depend on external libraries. A much-discussed feature of DotGNU is its implementation of the System.Windows.Forms library, which is used to build GUIs. System.Windows.Forms simplifies development by reducing dependence on other toolkits.
Getting the Tools
Some distro repositories carry DotGNU binaries, but it's a good idea to compile them from source. The tarballs are available on the DotGNU website , and you can also fetch them via CVS.
To get the compiler and libraries, install treecc, pnet, and the pnetlib packages. Optionally, the ml-pnet package lets you work with Mono's libraries, and the pnetC package enables the DotGNU compiler to compile C programs.
cvs -z3 -d:pserver:firstname.lastname@example.org:/sources/dotgnu-pnet co .
downloads the latest source of all DotGNU packages inside the directory it is issued from, so make sure it is under something like /opt/dotgnu. Now change to each directory and run ./auto_gen.sh for all the packages to generate the configuration and make files. Once that's completed, or if you just grabbed the tarball instead of checking out via CVS, the usual ./configure, make, make install (the last one, as usual, as root) will install the DotGNU compiler and libraries.
Buy this article as PDF
MSBuild is now just another GitHub project as Redmond continues its path to the light.
Malware could pass data and commands between disconnected computers without leaving a trace on the network.
New rules emphasize collegiality in coding.
Upstart lands in the dust bin as a new era begins for Linux.
HP's annual Cyber Risk report offers a bleak look at the state of IT.
But what do the big numbers really mean?
.NET Core execution engine is the basis for cross-platform .NET implementations.
The Xnote trojan hides itself on the target system and will launch a variety of attacks on command.
Spammers go low-volume, and 90% of IE browsers are unpatched.
Adobe scrambles to release patches for vulnerable Flash Player.