Write standards-compliant C# programs in Linux with DotGNU
Singing Sharp

© olly, Fotolia.com
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 [1], 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.
The command:
cvs -z3 -d:pserver:anonymous@cvs.sv.gnu.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
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Find SysAdmin Jobs
News
-
MNT Seeks Financial Backing for New Seven-Inch Linux Laptop
MNT Pocket Reform is a tiny laptop that is modular, upgradable, recyclable, reusable, and ships with Debian Linux.
-
Ubuntu Flatpak Remix Adds Flatpak Support Preinstalled
If you're looking for a version of Ubuntu that includes Flatpak support out of the box, there's one clear option.
-
Gnome 44 Release Candidate Now Available
The Gnome 44 release candidate has officially arrived and adds a few changes into the mix.
-
Flathub Vying to Become the Standard Linux App Store
If the Flathub team has any say in the matter, their product will become the default tool for installing Linux apps in 2023.
-
Debian 12 to Ship with KDE Plasma 5.27
The Debian development team has shifted to the latest version of KDE for their testing branch.
-
Planet Computers Launches ARM-based Linux Desktop PCs
The firm that originally released a line of mobile keyboards has taken a different direction and has developed a new line of out-of-the-box mini Linux desktop computers.
-
Ubuntu No Longer Shipping with Flatpak
In a move that probably won’t come as a shock to many, Ubuntu and all of its official spins will no longer ship with Flatpak installed.
-
openSUSE Leap 15.5 Beta Now Available
The final version of the Leap 15 series of openSUSE is available for beta testing and offers only new software versions.
-
Linux Kernel 6.2 Released with New Hardware Support
Find out what's new in the most recent release from Linus Torvalds and the Linux kernel team.
-
Kubuntu Focus Team Releases New Mini Desktop
The team behind Kubuntu Focus has released a new NX GEN 2 mini desktop PC powered by Linux.