More than just apps: 5 innovative uses for C#

We look at how scriptcs, Cake, ConfigR, Wyam, and Scripty are putting C# to innovative and unconventional uses.
444 readers like this.
Open innovation

Opensource.com

The .NET platform has always been a mainstay of the desktop and server app development field, powering Windows Forms, WPF, ASP.NET, and many years of Line of Business (LOB) apps. Today, however, .NET is a very different platform; it's powered by an open-source API-based compiler platform, features in-built scripting capabilities, and C# can be authored effectively in many IDEs, not just from Microsoft.

Thanks to these changes, there's been rapid growth in innovative and unconventional uses for C# and the whole .NET platform. Let's check out five of the most exciting projects:

1. scriptcs: scriptcs makes it easy to write and execute C# with a simple text editor.

scriptcs is one of the older projects on this list and one of the pioneers of IDE-free C#. scriptcs allows you to write simple, low-ceremony scripts using C# and your favorite text editor on Windows. Scripts have drastically simplified syntax compared to "traditional" C# apps and can be as simple as one-line C# snippets, or can use "script packs" to build a functioning ASP.NET Web API endpoint in just 10 lines of code. Plus, with support for referencing assemblies and installing packages out of the box, scriptcs lets you leverage the huge ecosystem of NuGet packages available, right in your scripts.

scriptcs is maintained by Glenn Block, Justin Rusbatch, and Filip Wojcieszyn and is available on GitHub under an Apache 2 license.

2. Cake: Cake (C# Make) is a cross-platform build-automation system with a C# DSL.

Cake is a cross-platform project for writing build-automation scripts in C# to do things such as compiling code, running tests, building packages, or just about anything else. Built on the Roslyn and Mono compilers, Cake lets you write your build scripts in C# and run them directly on Linux, Windows, and Mac OS, locally or on any CI platform of choice. With more than 100 community add-ins, Cake has support for everything from cloud storage, orchestration and messaging, to controlling containers, virtual machines, and web servers.

Cake is maintained by Patrik Svensson, Mattias Karlsson, Gary Ewan Park, and Alistair Chapman, and is available on GitHub under an MIT license.

3. ConfigR: Write your .NET configuration files in C#.

ConfigR is another Roslyn compiler-powered extension of the C# language, using a simple and flexible domain-specific language (DSL) to replace static configuration files (XML or JSON, for example) with C# code files. This allows not only for a simple and flexible configuration for .NET apps, but also allows for complex, nested, statically typed configuration that plugs right into your code, no XML needed. Because ConfigR is built on Roslyn, it also allows for referencing external assemblies and scripts so you even can share common configuration logic or retrieve configuration values from a remote server, all from one .csx file.

ConfigR was written by Adam Ralph, is maintained by Filip Wojcieszyn, and is available on GitHub under an MIT License.

4. Wyam: Wyam is a highly modular and extremely configurable static content generator and toolkit.

Wyam is an incredibly flexible static content toolkit powered by C# and the Roslyn compiler. Wyam can be used to generate anything from static websites, to online documentation, to complete blogs, and the engine behind Wyam even can be embedded in other .NET applications. The toolkit supports a wide range of technologies and formats, including common .NET technologies (like Razor templates), but also external types, such as Markdown, LESS styles, YAML parsing, and a built-in web server. Powering all of this flexibility, Wyam's configuration file is actually a fully featured C# script, complete with support for external add-ins and modules, classes, and anything else you can do in C#.

Wyam is maintained by Dave Glick and is available on GitHub under an MIT License.

5. Scripty: Tools to let you use Roslyn-powered C# scripts for code generation.

Pushing .NET into the realm of metaprogramming, Scripty is a cool project that uses C# scripts to generate C# code. Scripty, like the other projects here, is powered by the Roslyn compiler's scripting support, modified to create C# scripts that can be used for all kinds of code generation, so you can use C# to generate more C#. Because it's project- and compiler-aware, you can also build code-generation scripts to modify your project, generate app code based on existing files and logic, or even use scripts to embed resources in your compiled assets ready for deployment.

Scripty is maintained by Dave Glick and is available on GitHub under an MIT License.

Alistair Chapman
Alistair Chapman is an InfoSec Engineer, .NET developer and technical architect. While he's currently working at Red Hat, he's also done everything from network engineering to DevOps transformations. When not at work, Alistair is active in the .NET open-source community, including maintaining Cake (a .NET Foundation project). All opinions are my own, and do not represent Red Hat.

3 Comments

Thanks for sharing!

This is a great article! I've used Cake recently and and it's a great tool. Cake is also part of .NET foundation as well as .NET Core and Roslyn.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.