Exploring Future Tools: Roslyn, Next Generation Open-Source C# Compiler

The next major version of Visual Studio, currently known as Visual Studio “14”, will bring various changes in .NET development stack. These changes include .NET Framework and ASP.NET vNext, RyuJIT compiler, .NET Native and new C# compiler - Roslyn.

Project Roslyn was announced a few years ago as an attempt to redesign and modernize the C# and VB.NET compiler tools. C# and VB.NET compilers shipped with Visual Studio 2013 have a long history and carry a baggage from the early days of .NET. The current architecture limits languages evolution and speed of innovations.

Roslyn represents a new compiler created from the ground up using C#. Unlike previous generations of compilers, it is not a black magic box that accepts source code as an input and outputs binary files. Roslyn exposes code analysis and compilation APIs that can be used from .NET applications. Even better, Roslyn is open-sourced and published at roslyn.codeplex.com.

The benefits of Roslyn

All .NET developers will benefit from Roslyn by having new features in C# 6 and better code editing experience in next version of Visual Studio.

image

For Visual Studio extension developers, Roslyn provides code-parsing infrastructure allowing faster development of code analysis tools. Instead of spending time on new code parsers and analyzers, they can reuse Roslyn services and concentrate on delivering tool’s key features.

Other areas where Roslyn can significantly improve productivity are in-application scripting and custom business rules. Roslyn services can be used from .NET application to compile and execute dynamically generated code that opens wide range of interesting scenarios.

Why try Roslyn now

As any software product, existing C# and VB compilers are not bug-free. Developing a new compiler, the Roslyn team wrestled with the dilemma to keep bugs in new code or fix them. In some situations, the decision was to fix the bug even if it may break someone’s code. By verifying your solution with Roslyn now you may avoid surprises in the future and can record broken code as technical debt and be able to fix it without rush.

In addition, you can influence Roslyn development. By learning the project and participating in forums on CodePlex, you can advise development team on you needs, help with prioritization of features or even contribute to source code.

How to try Roslyn

The easiest way to try Roslyn is to use it through the Community Preview of Visual Studio “14”. It can be installed on the local system from an .iso image or evaluated from a prebuilt Azure VM image.

In either case, you will be able to explore new IDE features and play with language feature. New language features are disable by default but can be enabled for selected projects.

To enable C# 6 features, unload the selected project and edit it to add <LangVersion> section:

image

It will allow you to start using new features such as primary constructors, auto-property initializers, null propagating operator (?.) and others.

Simple as that!

Next Steps

Connect(); on November 12 and 13

clip_image001A cloud-first, mobile-first, developer-first , virtual eventDon’t miss Connect(); next week! Scott Guthrie, S. Somasegar, Brian Harry, and Scott Hanselman will take the stage to show innovative, new Microsoft products, services, and technologies including .NET, Azure, Visual Studio, and Visual Studio Online.

Dive deeper into the technical details behind the announcements with over 40 on-demand technical sessions. Interact with the Microsoft engineering teams in live sessions to get answers to your questions.
Come experience the new world of mobile-first, cloud-first development where you will build on your existing skills to unleash your creativity in the comfort of your office.

Check out the Connect(); for more details >>